<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    JBREFLECT-5 - Implementing generics in JavassistClassInfo
</h3>
<span style="margin-bottom: 10px;">
    reply from <a href="http://community.jboss.org/people/kabir.khan%40jboss.com">Kabir Khan</a> in <i>JBoss Microcontainer Development</i> - <a href="http://community.jboss.org/message/539875#539875">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><blockquote class="jive-quote"><p>Kabir Khan wrote:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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.</p></blockquote><p>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</p><p>a) Be slow</p><p>b) Might not be possible, i.e. maybe none of the classloaders for any of the bounds are able to load everything.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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 :-)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Java itself does not seem to reuse the ParameterizedTypes, as shown by this simple passing test:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> DeleteMe <font color="navy"><b>extends</b></font> ContainerTest
<font color="navy">{</font>
&#160;&#160; <font color="navy"><b>public</b></font> DeleteMe(String name)
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>super</b></font>(name);
&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160; <font color="navy"><b>public</b></font> Set&lt;String&gt; m1()<font color="navy">{</font><font color="navy"><b>return</b></font> <font color="navy"><b>null</b></font>;<font color="navy">}</font>
&#160;
&#160;&#160; <font color="navy"><b>public</b></font> Set&lt;String&gt; m2()<font color="navy">{</font><font color="navy"><b>return</b></font> <font color="navy"><b>null</b></font>;<font color="navy">}</font>
&#160;
&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> testType() <font color="navy"><b>throws</b></font> Exception
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; Type t1 = DeleteMe.class.getDeclaredMethod(<font color="red">"m1"</font>).getGenericReturnType();
&#160;&#160;&#160;&#160;&#160; Type t2 = DeleteMe.class.getDeclaredMethod(<font color="red">"m1"</font>).getGenericReturnType();
&#160;
&#160;&#160;&#160;&#160;&#160; ParameterizedType p1 = assertInstanceOf(t1, ParameterizedType.class);
&#160;&#160;&#160;&#160;&#160; ParameterizedType p2 = assertInstanceOf(t2, ParameterizedType.class);
&#160;
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//The param are equal, but not the same</font>
&#160;&#160;&#160;&#160;&#160; assertEquals(p1, p2);
&#160;&#160;&#160;&#160;&#160; assertNotSame(p1, p2);
&#160;
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//The raw types are the same</font>
&#160;&#160;&#160;&#160;&#160; assertSame(p1.getRawType(), p2.getRawType());
&#160;&#160;&#160;&#160;&#160; assertEquals(1, p1.getActualTypeArguments().length);
&#160;&#160;&#160;&#160;&#160; assertEquals(1, p2.getActualTypeArguments().length);
&#160;&#160;&#160;&#160;&#160; Class&lt;?&gt; clazz1 = assertInstanceOf(p1.getActualTypeArguments()[0], Class.class);
&#160;&#160;&#160;&#160;&#160; Class&lt;?&gt; clazz2 = assertInstanceOf(p2.getActualTypeArguments()[0], Class.class);
&#160;&#160;&#160;&#160;&#160; assertSame(clazz1, clazz2);
&#160;&#160; <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><div> </div></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/539875#539875">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Microcontainer Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2115">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>