Date: Wed, 14 May 2003 13:55:37 -0400 (EDT)
From: C. Scott Ananian
To: jsr14-prototype-comments@sun.com
Subject: Verify error in 1.3 prototype.
This code, compiled with the 1.3 prototype (also the 1.0 and 1.2
prototypes):
import java.util.*;
class A {
public static void main (String argv[]) {
ArrayList<Boolean> B = new ArrayList<Boolean>(10);
Iterator<Boolean> i = B.iterator();
boolean b = (i.next()).booleanValue();
}
}
causes a verify error when it is run:
cananian@skiffserv:~/SUNBUG$ java A
Exception in thread "main" java.lang.VerifyError: (class: B, method:
methodC signature: ()V) Incompatible object argument for function call
at A.main(Test.java:5)
cananian@skiffserv:~/SUNBUG$
Examining the bytecode makes it obvious that a required typecast is
missing:
Codeview "bytecode" for public static void A.main(java.lang.String[]):
#3/A.java:5 - new class java.util.ArrayList
#4/A.java:5 - dup
#5/A.java:5 - bipush (byte)10
#6/A.java:5 - invokespecial public java.util.ArrayList(int)
#7/A.java:5 - astore_1 lv_1
#8/A.java:6 - aload_1 lv_1
#9/A.java:6 - invokevirtual public java.util.Iterator java.util.AbstractList.iterator()
#10/A.java:6 - astore_2 lv_2
#11/A.java:7 - aload_2 lv_2
#12/A.java:7 - invokeinterface public abstract java.lang.Object java.util.Iterator.next()
#13/A.java:7 - invokevirtual public final boolean java.lang.Boolean.booleanValue()
#14/A.java:7 - istore_3 lv_3
#15/A.java:8 - return
There should be a typecast between #12 and #13.
This was discovered by "agentsmooth" on the GJ forums:
http://forum.java.sun.com/thread.jsp?forum=316&thread=398785
(as noted on the forum) removing the parentheses around 'i.next()' in the
example is a valid workaround:
Codeview "bytecode" for public static void A2.main(java.lang.String[]):
#3/A2.java:5 - new class java.util.ArrayList
#4/A2.java:5 - dup
#5/A2.java:5 - bipush (byte)10
#6/A2.java:5 - invokespecial public java.util.ArrayList(int)
#7/A2.java:5 - astore_1 lv_1
#8/A2.java:6 - aload_1 lv_1
#9/A2.java:6 - invokevirtual public java.util.Iterator java.util.AbstractList.iterator()
#10/A2.java:6 - astore_2 lv_2
#11/A2.java:7 - aload_2 lv_2
#12/A2.java:7 - invokeinterface public abstract java.lang.Object java.util.Iterator.next()
#13/A2.java:7 - checkcast class java.lang.Boolean
#14/A2.java:7 - invokevirtual public final boolean java.lang.Boolean.booleanValue()
#15/A2.java:7 - istore_3 lv_3
#16/A2.java:8 - return
Note the new presence of instruction #13.
--scott
chemical agent cracking Uzi Soviet Mk 48 IDEA East Timor Minister
TASS colonel BATF assassination politics Justice Panama Albanian Leitrim
( http://cscott.net/ )