Bug 89632 - Exception when trying to evaluate in Snippet Editor
Summary: Exception when trying to evaluate in Snippet Editor
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 3.1 RC1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-30 13:10 EST by Samantha Chan CLA
Modified: 2005-05-27 04:51 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samantha Chan CLA 2005-03-30 13:10:38 EST
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)
Comment 1 Darin Wright CLA 2005-03-30 17:46:44 EST
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...).
Comment 2 Darin Wright CLA 2005-04-25 11:21:17 EDT
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.
Comment 3 Olivier Thomann CLA 2005-05-17 14:18:25 EDT
Reproduced. I am investigating.
Comment 4 Olivier Thomann CLA 2005-05-17 14:39:55 EDT
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.
Comment 5 Olivier Thomann CLA 2005-05-17 15:55:56 EDT
Update CodeSnippetMessageSend.
Fixed and released in HEAD.
Regression test added in
org.eclipse.jdt.core.tests.eval.CodeSnippetTest.testFor89632
Comment 6 Frederic Fusier CLA 2005-05-27 04:51:52 EDT
Verified for 3.1 RC1 with build I20050527-0010.