Note that there are some explanatory texts on larger screens.

plurals
  1. POJava inner class inconsistency between descriptor and signature attribute? (class file)
    primarykey
    data
    text
    <p>I'm trying to understand if there's a reason in the spec for the discrepany between java descriptors and signatures for inner classes. (I'm looking directly at the content of the class files here, but I use javap to illustrate).</p> <p>( n.b. I have tried this on JDK 1.6.0_33 and 1.7.0_05, both have the same issue <em>when viewed with javap from Java 7</em> - java 6's javap doesn't seem to show any generic signature info, as per Sean's answer below. )</p> <p>Update : Thanks to those discussing - my take is</p> <ul> <li>The descriptor (which doesn't contain generic information) is correct. </li> <li>The signature (which is an attribute of the method, and does contain generic information) is incorrect. The relevant ConstPool entry for SIGNATURE of the &lt;init&gt; method is " ConstantUTF8[(Ljava/util/list&lt;TE;&gt;)V] "</li> <li>Javap in Java 6 doesn't LOOK at the signature, just the descriptor. (My guess!)</li> </ul> <p>In case anyone wonders, I hit this without using JAVAP, just looking at the class files myself, I am only using javap to show it. (so it's unlikely to be a javap bug).</p> <p>Consider:</p> <pre><code>public class InnerClassTest1 { public int getX() { return new Inner1(new ArrayList&lt;String&gt;()).getX(4); } public class Inner1 { private final List arg; public Inner1(List arg) { this.arg = arg; }.... </code></pre> <p>vs</p> <pre><code>public class InnerClassTest2 { public int getX() { return new Inner1(new ArrayList&lt;String&gt;()).getX(4); } public class Inner1&lt;E&gt; { private final List&lt;E&gt; arg; public Inner1(List&lt;E&gt; arg) { this.arg = arg; }..... </code></pre> <p>If you look at the output of javap -cs on the inner classes, they're surprisingly different!</p> <p>public org.benf.cfr.tests.InnerClassTest1$Inner1(<strong>org.benf.cfr.tests.InnerClassTest1,</strong> java.util.List); Signature: (Lorg/benf/cfr/tests/InnerClassTest1;Ljava/util/List;)V</p> <p>vs</p> <p>public org.benf.cfr.tests.InnerClassTest2$Inner1(java.util.List&lt;E&gt;); Signature: (Lorg/benf/cfr/tests/InnerClassTest2;Ljava/util/List;)V</p> <p>... <em>the one which uses generics is missing the implicit parameter for the outer class!</em> (it's correctly present in InnerClassTest1).</p> <p>I can't find anything in the class file documentation to explain this - does anyone know why this might be?</p> <p>Thanks!</p> <p>Lee.</p> <hr> <p>Update - </p> <p>I've placed example files at <a href="http://www.benf.org/files/innerClassTest.tgz" rel="nofollow" title="example files &#40;tgz&#41;">http://www.benf.org/files/innerClassTest.tgz</a></p> <p>Given Sean's answer below, I tried using javap on java 6, and I saw identical output for both, with no generic information - this leads me to believe that java 6's javap is not displaying full signature information?</p> <p>The exact output I get using javap on 1.7.0_05-b06 is</p> <pre><code>public class org.benf.cfr.tests.InnerClassTest2$Inner1&lt;E&gt; { final org.benf.cfr.tests.InnerClassTest2 this$0; Signature: Lorg/benf/cfr/tests/InnerClassTest2; public org.benf.cfr.tests.InnerClassTest2$Inner1(java.util.List&lt;E&gt;); Signature: (Lorg/benf/cfr/tests/InnerClassTest2;Ljava/util/List;)V Code: 0: aload_0 1: aload_1 2: putfield #1 // Field this$0:Lorg/benf/cfr/tests/InnerClassTest2; 5: aload_0 6: invokespecial #2 // Method java/lang/Object."&lt;init&gt;":()V 9: aload_0 10: aload_2 11: putfield #3 // Field arg:Ljava/util/List; 14: return public int getX(int); Signature: (I)I Code: 0: iconst_2 1: ireturn } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload