Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Moller2013-03-20 16:28:13 +0000
committerJayaprakash Arthanareeswaran2013-03-20 16:28:13 +0000
commit18898f0d612eb2e52a6adfb84babe3548ca0ae34 (patch)
tree982a0b7e22740fb26c676718f701c0933fca5e60
parent8d2baa99076f461eca8896e0dcb45cebd9c68005 (diff)
downloadeclipse.jdt.core-18898f0d612eb2e52a6adfb84babe3548ca0ae34.tar.gz
eclipse.jdt.core-18898f0d612eb2e52a6adfb84babe3548ca0ae34.tar.xz
eclipse.jdt.core-18898f0d612eb2e52a6adfb84babe3548ca0ae34.zip
Fixed Bug 401853 - Eclipse Java compiler creates invalid bytecode
(java.lang.VerifyError)
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java79
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java15
2 files changed, 91 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java
index 13f6920dae..0e7db8fddb 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Jesper S Moller - Contribution for
+ * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -2833,6 +2835,81 @@ public void test054() throws Exception {
"Zork cannot be resolved to a type\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401853
+// Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
+public void test057() throws Exception {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static void main(String[] argv) {\n" +
+ " for (long l : new ArrayList<Long>()) {}\n" +
+ " }\n" +
+ "}",
+ },
+ "",
+ null,
+ true,
+ null,
+ options,
+ null);
+
+ String expectedOutput =
+ "public class X {\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [8]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 3]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" +
+ " // Stack: 2, Locals: 2\n" +
+ " public static void main(java.lang.String[] argv);\n" +
+ " 0 new java.util.ArrayList [16]\n" +
+ " 3 dup\n" +
+ " 4 invokespecial java.util.ArrayList() [18]\n" +
+ " 7 invokevirtual java.util.ArrayList.iterator() : java.util.Iterator [19]\n" +
+ " 10 astore_1\n" +
+ " 11 goto 27\n" +
+ " 14 aload_1\n" +
+ " 15 invokeinterface java.util.Iterator.next() : java.lang.Object [23] [nargs: 1]\n" +
+ " 20 checkcast java.lang.Long [29]\n" +
+ " 23 invokevirtual java.lang.Long.longValue() : long [31]\n" +
+ " 26 pop2\n" +
+ " 27 aload_1\n" +
+ " 28 invokeinterface java.util.Iterator.hasNext() : boolean [35] [nargs: 1]\n" +
+ " 33 ifne 14\n" +
+ " 36 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 5]\n" +
+ " [pc: 36, line: 6]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 37] local: argv index: 0 type: java.lang.String[]\n";
+
+ File f = new File(OUTPUT_DIR + File.separator + "X.class");
+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
+ int index = result.indexOf(expectedOutput);
+ if (index == -1 || expectedOutput.length() == 0) {
+ System.out.println(Util.displayString(result, 3));
+ }
+ if (index == -1) {
+ assertEquals("Wrong contents", expectedOutput, result);
+ }
+}
+
public static Class testClass() {
return ForeachStatementTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java
index 4456f6eff6..48bdd826c2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForeachStatement.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,8 @@
* bug 349326 - [1.7] new warning for missing try-with-resources
* bug 370930 - NonNull annotation not considered for enhanced for loops
* bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
+ * Jesper S Moller - Contribution for
+ * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -31,6 +33,7 @@ import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.TagBits;
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
+import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
public class ForeachStatement extends Statement {
@@ -301,7 +304,15 @@ public class ForeachStatement extends Statement {
}
}
if (this.elementVariable.binding.resolvedPosition == -1) {
- codeStream.pop();
+ switch (this.elementVariable.binding.type.id) {
+ case TypeIds.T_long :
+ case TypeIds.T_double :
+ codeStream.pop2();
+ break;
+ default:
+ codeStream.pop();
+ break;
+ }
} else {
codeStream.store(this.elementVariable.binding, false);
codeStream.addVisibleLocalVariable(this.elementVariable.binding);

Back to the top