Re: generics interface

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: generics interface

Tim Fennell-3
So, I tried to reply to this thread this morning, but my ISP has totally screwed up my email over the last two days, and i think the response got eaten.  At any rate, I have some good news.

I turned Andy's code into a simpler test case and then threw it into the debugger to determine exactly what's going on, and more specifically how to actually get at the type information that we want.  As Taras pointed out, the PropertyDescriptor that gets returned in this case is, for practical purposes, incorrect.

From reading up it would appear that the compiler generates a bridge method for any concrete implementation of an interface method that involves a type variable that is parameterized in the class.  E.g in Andy's case the XX interface has a type variable, and the class BB implements XX and provides the type parameter CC.

A bit of poking shows that you can actually get around this by basically doing:
    Method m = pd.getReadMethod();
    if (m.isBridge()) m = m.getDeclaringClass().getMethod(m.getName());

which returns the correct, non-bridge method.  Doing the same for write-only properties is a little less tractable, but it would seem like looping through all the methods to find a non-bridge method of the same name with only a single parameter should be pretty safe.

I'm going to create a bug, and then check in my fixes and merge them onto the 1.4 branch so they'll be available in 1.4.2.

-t

ps. I took a quick look at the linked bug earlier, but Sun's bug database is down for maintenance now.  I can't quite decide if I think the above is a bug in the JDK or not.  It would seem like you could make a good argument that the PropertyDescriptor *should* return the bridge methods since this is how type safety is enforced in these situations, but also that it should report the property type correctly...I guess we'll see.

On Oct 12, 2006, at 11:10 AM, Taras Puchko wrote:

Hi all,
 
Just FYI, there is a J2SE bug in progress: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6422403
 
As a workaround Stripes could verify introspection results using reflection...

-Taras
 
On 10/12/06, Andy <[hidden email]> wrote:
Hi all,

On Thu, 12 Oct 2006, Taras Puchko wrote:
> I guess I know the answer. It's because java.beans.Introspector is used and
> it has a different behavior.

Thanks :)

On Thu, 12 Oct 2006, Jasper Fontaine wrote:
> maybe let Stripes look to the method signatures a bit more when the
> return type is actually of class java.lang.Object?

This may not be the case. Changing Taras's code to

interface X<T extends CharSequence> {...}

I get

public final native java.lang.Class java.lang.Object.getClass()
public volatile java.lang.CharSequence Temp.getT()

so it may not always be Object.

- Andy

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
Stripes-users mailing list


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users