Broken bytecode for enhanced-for loop with inferred type array expression
Issue #261
resolved
ExtendJ 8.1.0-4-ge296850 Java SE 7
The following generates broken bytecode:
import java.util.Set;
import java.util.Collections;
public class An3 {
public static void main(String[] args) {
foo(Collections.singleton("x marks the spot"));
}
static void foo(Set<String> set) {
for (String msg : set.toArray(new String[set.size()])) {
System.out.println(msg);
}
}
}
Expected result: the program should print x marks the spot
Actual result: the compiled program fails to run with this error:
Exception in thread "main" java.lang.VerifyError: Instruction type does not match stack map
Exception Details:
Location:
An3.foo(Ljava/util/Set;)V @21: iload_2
Reason:
Type '[Ljava/lang/Object;' (current frame, locals[1]) is not assignable to '[Ljava/lang/String;' (stack map, locals[1])
...
Comments (2)
-
reporter -
reporter - changed status to resolved
Fix enhanced-for code generation issue
Fixed problem in casting conversions when using array types in enhanced for statements.
fixes
#261(bitbucket)→ <<cset eed723d1da7b>>
- Log in to comment
It seems like the problem is a missing
CHECKCAST
to convert the erased result oftoArray
to[Ljava/lang/String;
.