Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper S Moller2013-02-27 16:06:04 +0000
committerssankaran2013-02-27 16:07:12 +0000
commitd50236df9926d94803c8204bb857934d9e16640c (patch)
tree9c278dc03f487909ec618e564217ae20cb98b205
parentb3437a91900d945d521cc99350d7763410302951 (diff)
downloadeclipse.jdt.core-d50236df9926d94803c8204bb857934d9e16640c.tar.gz
eclipse.jdt.core-d50236df9926d94803c8204bb857934d9e16640c.tar.xz
eclipse.jdt.core-d50236df9926d94803c8204bb857934d9e16640c.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 4c1edd5346..78c5e7ec9b 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
@@ -9,6 +9,8 @@
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contribution for
* bug 393719 - [compiler] inconsistent warnings on iteration variables
+ * Jesper S Moller - Contribution for
+ * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -2906,6 +2908,81 @@ public void test056() 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 5538ce4151..d467e837f8 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
@@ -13,6 +13,8 @@
* bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations
* bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null"
* bug 393719 - [compiler] inconsistent warnings on iteration variables
+ * Jesper S Moller - Contribution for
+ * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError)
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -33,6 +35,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 {
@@ -304,7 +307,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