Kabir Khan [
http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the
discussion
"JBREFLECT-5 - Implementing generics in JavassistClassInfo"
To view the discussion, visit:
http://community.jboss.org/message/539875#539875
--------------------------------------------------------------
Kabir Khan wrote:
One way around this would be in mi.getReturnType() when looking up/creating/caching the
parameterized class info to use the classloader of
mi.getDeclaringClass().getClassLoader(), which should be able to see all the classes
involved. However, I am still stuck on which classloader to use for my previous post.
This works, however for "1 - other problem" I don't really see a way
to determine the classloader. It could be the classloader of the raw type, or the loader
of any of the class infos. It might be possible to determine which of the classloaders can
see all the generic bounds by brute force, but that will probably
a) Be slow
b) Might not be possible, i.e. maybe none of the classloaders for any of the bounds are
able to load everything.
I have tried turning off caching for these parameterized ClassInfos, which causes some of
the tests to fail. From what I can see fixing them means having to adjust some of the
tests to use assertEquals() instead of assertSame() for parameterized ClassInfos. I think
this is necessary, and that the idea of enforcing object equality for parameterized
ClassInfos is a misunderstanding :-)
Java itself does not seem to reuse the ParameterizedTypes, as shown by this simple passing
test:
public class DeleteMe extends ContainerTest
{
public DeleteMe(String name)
{
super(name);
}
public Set<String> m1(){return null;}
public Set<String> m2(){return null;}
public void testType() throws Exception
{
Type t1 = DeleteMe.class.getDeclaredMethod("m1").getGenericReturnType();
Type t2 = DeleteMe.class.getDeclaredMethod("m1").getGenericReturnType();
ParameterizedType p1 = assertInstanceOf(t1, ParameterizedType.class);
ParameterizedType p2 = assertInstanceOf(t2, ParameterizedType.class);
//The param are equal, but not the same
assertEquals(p1, p2);
assertNotSame(p1, p2);
//The raw types are the same
assertSame(p1.getRawType(), p2.getRawType());
assertEquals(1, p1.getActualTypeArguments().length);
assertEquals(1, p2.getActualTypeArguments().length);
Class<?> clazz1 = assertInstanceOf(p1.getActualTypeArguments()[0],
Class.class);
Class<?> clazz2 = assertInstanceOf(p2.getActualTypeArguments()[0],
Class.class);
assertSame(clazz1, clazz2);
}
}
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/539875#539875]
Start a new discussion in JBoss Microcontainer Development at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]