Community
Participate
Working Groups
Testcase: Collection<String> c = new ArrayList<String>(); c.add("a"); c.add("b"); c.add("c"); for (Iterator<String> i = c.iterator(); i.hasNext(); ) if (i.next().length() == 4) { String x = i.next(); System.out.println(x); } return c; I added the testcase to the snippet editor. I then did a "Set Imports..." to include java.util.* to resolve collection and iterator. Trying a "Display" or "Inspect" resulted in the following error in the console: java.lang.VerifyError: arguments are not type compatible (class: CodeSnippet_2 method: run()V) at pc: 57 at java.lang.Class.verifyImpl(Native Method) at java.lang.Class.verify(Class.java:254) at java.lang.Class.initialize(Class.java:317) at java.lang.Class.forNameImpl(Native Method) at java.lang.Class.forName(Class.java:128) at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1.eval (ScrapbookMain1.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:46) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:611) at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.evalLoop (ScrapbookMain.java:54) at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.main (ScrapbookMain.java:35)
I think this may be due to the fact that the snippet support jar is compiled against 1.4, and is running on 1.5 (however, I thought a 1.5 VM would run 1.4 files...).
This simpler snippet also causes the problem: Collection<String> c = new ArrayList<String>(); c.add("a"); c.add("b"); c.add("c"); Iterator<String> i = c.iterator(); while (i.hasNext()) { System.out.println(i.next()); } If I remove the <String> qualifier from Iterator, then it works. Moving to JCORE for investigation. It looks like the problem is coming from the classfile generated by the IEvaluationContext. The scrapbook page is created in a Java project with 1.5 compilation options.
Reproduced. I am investigating.
The code generated for the code snippet missed a checkcast. 0 new java/util/ArrayList [19] 3 dup 4 invokespecial java/util/ArrayList.<init>()V [20] 7 astore_1 [c] 8 aload_1 [c] 9 ldc <String "a"> [22] 11 invokeinterface java/util/Collection.add(Ljava/lang/Object;)Z [28] [nargs: 2] 16 pop 17 aload_1 [c] 18 ldc <String "b"> [30] 20 invokeinterface java/util/Collection.add(Ljava/lang/Object;)Z [28] [nargs: 2] 25 pop 26 aload_1 [c] 27 ldc <String "c"> [32] 29 invokeinterface java/util/Collection.add(Ljava/lang/Object;)Z [28] [nargs: 2] 34 pop 35 aload_1 [c] 36 invokeinterface java/util/Collection.iterator()Ljava/util/Iterator; [36] [nargs: 1] 41 astore_2 [i] 42 goto 57 45 getstatic java/lang/System.out Ljava/io/PrintStream; [42] 48 aload_2 [i] 49 invokeinterface java/util/Iterator.next()Ljava/lang/Object; [48] [nargs: 1] // CHECKCAST NEEDED HERE TO CONVERT TO A STRING 54 invokevirtual java/io/PrintStream.println(Ljava/lang/String;)V [54] 57 aload_2 [i] 58 invokeinterface java/util/Iterator.hasNext()Z [58] [nargs: 1] 63 ifne 45 66 return I will investigate why the checkcast is missing.
Update CodeSnippetMessageSend. Fixed and released in HEAD. Regression test added in org.eclipse.jdt.core.tests.eval.CodeSnippetTest.testFor89632
Verified for 3.1 RC1 with build I20050527-0010.