Community
Participate
Working Groups
I know, you are not finished, but just some feedback for type annotations: If you compile the following with the Eclipse Compiler: (Size is an easy Type Annotation with 1 argument for wasier debugging) List<@Size(max = 41) CharSequence>[] @Size(max = 42) [] @Nonnull @Size(max = 43) [][] test = new @Size(max = 44) ArrayList @Size(max = 45) [10][][] @Size(max = 47) @Size(max = 48) []; Then we find multiple (none-cosmetic) differences in the compiled byte in comparision to JDK 8 (most recent build), some of them not spec conform I think. 1.) No attribute "Local variable type table" with the generic type info for the variable is rendered, I know generic array declarations are somewhat so-so from spec view. JDK 8 generates this happily... (But you generate the type annotation info for the CharSequence type param.) 2.) Size(44) till Size(4) appear 2 times in the Bytecode, one is correct int he array structure, but you generate it again for the local variable. So they appear at the wrong place, whats against the spec (not repeatable type annotations can appear multiple times) 3.) The new operation has offset 2, if new is the second operation. I think thats like described (fuzzily) in the spec. The JDK 8 has the previos operation pc as offset! So you are different. I think the JDK is wrong here, you might have shorter/stronger communication lines to the JDK team?! 4) Little bit different topic, but same stuff for me: Java Bytecode Viewer doesn't show class level type annotation attributes...
BTW: whole test method: public static String testArrays() { List<@Size(max = 41) CharSequence>[] @Size(max = 42) [] @Nonnull @Size(max = 43) [][] test = new @Size(max = 44) ArrayList @Size(max = 45) [10][][] @Size(max = 47) @Size(max = 48) []; return (@Size(max = 49) String) test[0][1][2][3].get(0); } Decompiled from this: public static String testArrays() { @Size(max = 44) @Size(max = 45) @Size(max = 47) @Size(max = 48) java.util.List[] @Size(max = 42) [] @Nonnull @Size(max = 43) [][] test = new @Size(max = 44) java. util. ArrayList @Size(max = 45) [10][][] @Size(max = 47) @Size(max = 48) []; return (@Size(max = 49) String) test[0][1][2][3].get(0); } The initial Sizes are wrong and the generic info is lost for Eclipse compiler (not for Oracle Compiler)
(In reply to André Pankraz from comment #0) > I know, you are not finished, but just some feedback for type annotations: Actually, for 308 & 269, 118 and 120, the compiler work is finished, so defect reports are welcome. (actually also for 335) > 3.) The new operation has offset 2, if new is the second operation. I think > thats like described (fuzzily) in the spec. The JDK 8 has the previos > operation pc as offset! So you are different. I think the JDK is wrong here, > you might have shorter/stronger communication lines to the JDK team?! Directly reporting this to Oracle bug tracking system is the most effective way. > 4) Little bit different topic, but same stuff for me: Java Bytecode Viewer > doesn't show class level type annotation attributes... Are you referring to javap ? If so, that being an Oracle tool, issues are better reported there. But what do you mean by class level type annotation attributes ? TYPE_USE annotations at the (SE5) class declaration site end up in the same table as SE5 annotations per specification.
Andy, thanks for following up.
Hi, with 4) Java Bytecode Viewer I meant your org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor This ClassFileEditor viewer is quite good to debug such stuff (even though I'm really missing to click into Outline and then he jumps to the proper method here...). It's showing the attribute "RuntimeVisibleTypeAnnotations" at method level but it doesn't show the attribute on class level (I just call it that way, don't know your internal terms), where I could see the type annotations for class declarations type arguments, super classes or interfaces. 3) OK, will try later. Should really be same for Eclipse and JDK....and I think Eclipse is right with this. Best regards
Created attachment 239410 [details] Addresses the duplicate problem This fixes the problem of duplicates in the bytecode and includes a testcase. The problem was that the initializer was visited twice. The solution I included in the patch was to skip the initializer during the visit that collects the type annotations, it will be collected in the right way elsewhere. With those duplicates removed we are in much better shape. The one remaining annoyance I see is that there are two CHECKCASTs in what we generated for the test program. The first is generated by the MessageSend because it is seen to involve generics, the second is generated by the cast expression (because the cast has a type annotation). It isn't a problem as such but the bytecode is suboptimal.
Thanks for the patch Andy, looks good. I added a test for field initializers and released it here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=bbab5540f6141654f88ccf247a378547f83d5cdb (In reply to André Pankraz from comment #0) > 1.) No attribute "Local variable type table" with the generic type info for > the variable is rendered, I know generic array declarations are somewhat > so-so from spec view. JDK 8 generates this happily... > (But you generate the type annotation info for the CharSequence type param.) > 4) Little bit different topic, but same stuff for me: Java Bytecode Viewer > doesn't show class level type annotation attributes... I double checked this and couldn't find anything wrong in ECJ behavior: For this program: import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; @Retention(RetentionPolicy.RUNTIME) @Target(TYPE_USE) @interface Marker {} public class X extends @Marker Object {} We emit: " RuntimeVisibleTypeAnnotations: \n" + " #17 @Marker(\n" + " target type = 0x10 CLASS_EXTENDS\n" + " type index = -1\n" + " )\n"; I have raised https://bugs.eclipse.org/bugs/show_bug.cgi?id=427753 for follow up. Thanks!
Verified as working for Eclipse + Java 8 RC1 using Kepler SR2(RC4) + Eclipse Java Development Tools Patch for Java 8 Support (BETA) 1.0.0.v20140220-2054