diff options
author | Sasikanth Bharadwaj | 2017-01-03 06:12:45 +0000 |
---|---|---|
committer | Sasikanth Bharadwaj | 2017-01-04 06:18:22 +0000 |
commit | ca57a44373e7997152f841e41a1ddebb10d38e0d (patch) | |
tree | 0b9af6c7084c086d50f6c7ee29c1d8aed8ced3f5 | |
parent | 20f2eba1cc97728e4b2d5cc2872ce66fe99d4eeb (diff) | |
download | eclipse.jdt.core-R3_6_maintenance_Java7.tar.gz eclipse.jdt.core-R3_6_maintenance_Java7.tar.xz eclipse.jdt.core-R3_6_maintenance_Java7.zip |
[404146] [1.7][compiler] nested try-catch-finally-blocks leads toR3_6_maintenance_Java7
unrunnable Java byte code
Change-Id: Iabac2ac158e2cef3a3aa5a977f113912cb479bf3
7 files changed, 210 insertions, 7 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java index eb6e3f7e77..c496695fb5 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 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 @@ * Stephan Herrmann - Contribution for bug 236385 * Stephan Herrmann - Contribution for bug 295551 * Stephan Herrmann <stephan@cs.tu-berlin.de> - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + * Jesper Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -1795,6 +1797,7 @@ public void test012b(){ " </command_line>\n" + " <options>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode\" value=\"disabled\"/>\n" + + " <option key=\"org.eclipse.jdt.core.compiler.codegen.shareCommonFinallyBlocks\" value=\"disabled\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.targetPlatform\" value=\"1.5\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.codegen.unusedLocal\" value=\"optimize out\"/>\n" + " <option key=\"org.eclipse.jdt.core.compiler.compliance\" value=\"1.5\"/>\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java index ba8feb82d2..ffc51f7f98 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2011 IBM Corporation and others. + * Copyright (c) 2003, 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,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Moller - bug 404146 nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -1167,6 +1168,48 @@ public void test032() { // no finally }, "Done"); } +//Bug 404146 - nested try-catch-finally-blocks leads to unrunnable Java byte code +public void testBug404146() { + runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import javax.naming.NamingException;\n" + + + "\n" + + "public final class X {\n" + + "\n" + + " public static final void illegalStackMap() {\n" + + " try {\n" + + " try {\n" + + " Y.decoy1();\n" + + " } finally {\n" + + " try {\n" + + " Y.decoy2();\n" + + " } catch (final IOException e) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " } finally {\n" + + " try {\n" + + " Y.decoy3();\n" + + " } catch (final NamingException e) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + "Y.java", + "import java.io.IOException;\n" + + "import javax.naming.NamingException;\n" + + "public final class Y {\n" + + "\n" + + " public static void decoy1() {}\n" + + " public static void decoy2() throws IOException {}\n" + + " public static void decoy3() throws NamingException {}\n" + + "}\n" + }); +} public static Class testClass() { return TryStatement17Test.class; } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java index 21eb28d3f4..9e29231d82 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Jesper Steen Moller - Contribution for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -33,6 +35,11 @@ public TryStatementTest(String name) { public static Test suite() { return buildAllCompliancesTestSuite(testClass()); } +protected Map getCompilerOptions() { + Map compilerOptions = super.getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.ENABLED); + return compilerOptions; +} public void test001() { this.runConformTest(new String[] { "p/X.java", @@ -2361,6 +2368,128 @@ public void test042() throws Exception { assertEquals("Wrong contents", expectedOutput, result); } } + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=404146 - variation without sharing of inlined escaping finally-blocks +public void test042_not_shared() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_InlineJsr, CompilerOptions.ENABLED); + + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(args));\n" + + " }\n" + + " String foo(String[] args) {\n" + + " try {\n" + + " if (args == null) return \"KO\";\n" + + " switch(args.length) {\n" + + " case 0:\n" + + " return \"OK\";\n" + + " case 1:\n" + + " return \"KO\";\n" + + " case 3:\n" + + " return \"OK\";\n" + + " default:\n" + + " return \"KO\";\n" + + " }\n" + + " } finally {\n" + + " System.out.print(\"FINALLY:\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "FINALLY:OK", + null, + true, + null, + customOptions, + null); + + String expectedOutput = + " // Method descriptor #26 ([Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 2, Locals: 3\n" + + " java.lang.String foo(java.lang.String[] args);\n" + + " 0 aload_1 [args]\n" + + " 1 ifnonnull 15\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 7 ldc <String \"FINALLY:\"> [35]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 12 ldc <String \"KO\"> [40]\n" + + " 14 areturn\n" + + " 15 aload_1 [args]\n" + + " 16 arraylength\n" + + " 17 tableswitch default: 81\n" + + " case 0: 48\n" + + " case 1: 59\n" + + " case 2: 81\n" + + " case 3: 70\n" + + " 48 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 51 ldc <String \"FINALLY:\"> [35]\n" + + " 53 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 56 ldc <String \"OK\"> [42]\n" + + " 58 areturn\n" + + " 59 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 62 ldc <String \"FINALLY:\"> [35]\n" + + " 64 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 67 ldc <String \"KO\"> [40]\n" + + " 69 areturn\n" + + " 70 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 73 ldc <String \"FINALLY:\"> [35]\n" + + " 75 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 78 ldc <String \"OK\"> [42]\n" + + " 80 areturn\n" + + " 81 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 84 ldc <String \"FINALLY:\"> [35]\n" + + " 86 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 89 ldc <String \"KO\"> [40]\n" + + " 91 areturn\n" + + " 92 astore_2\n" + + " 93 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 96 ldc <String \"FINALLY:\"> [35]\n" + + " 98 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 101 aload_2\n" + + " 102 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 4] -> 92 when : any\n" + + " [pc: 15, pc: 48] -> 92 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 48, line: 19]\n" + + " [pc: 56, line: 10]\n" + + " [pc: 59, line: 19]\n" + + " [pc: 67, line: 12]\n" + + " [pc: 70, line: 19]\n" + + " [pc: 78, line: 14]\n" + + " [pc: 81, line: 19]\n" + + " [pc: 89, line: 16]\n" + + " [pc: 92, line: 18]\n" + + " [pc: 93, line: 19]\n" + + " [pc: 101, line: 20]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 103] local: this index: 0 type: X\n" + + " [pc: 0, pc: 103] local: args index: 1 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); + } +} + + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=128705 - variation public void test043() throws Exception { this.runConformTest( diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java index ecb7387693..2219adb049 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2011 IBM Corporation and others. + * Copyright (c) 2005, 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 Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -3815,6 +3817,8 @@ public void test014() { ""); } public void test015() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.ENABLED); runConformTest( true, new String[] { @@ -11840,6 +11844,8 @@ public void test015() { " }\n" + "}"}, null, + settings, + null, "Enter finally block\n" + "Inside finally block\n" + "Leave finally block\n" + diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java index 1919dcb34b..4854d9b17b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java @@ -10,6 +10,8 @@ * Stephan Herrmann - Contributions for * bug 332637 - Dead Code detection removing code that isn't dead * bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis + * Jesper Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -18,6 +20,7 @@ import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.*; @@ -857,7 +860,8 @@ public boolean generateSubRoutineInvocation(BlockScope currentScope, CodeStream return false; } // optimize subroutine invocation sequences, using the targetLocation (if any) - if (targetLocation != null) { + CompilerOptions options = this.scope.compilerOptions(); + if (options.shareCommonFinallyBlocks && targetLocation != null) { boolean reuseTargetLocation = true; if (this.reusableJSRTargetsCount > 0) { nextReusableTarget: for (int i = 0, count = this.reusableJSRTargetsCount; i < count; i++) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 5d705d6458..54130082fd 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 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 @@ -10,6 +10,8 @@ * Benjamin Muskalla - Contribution for bug 239066 * Stephan Herrmann - Contribution for bug 236385 * Stephan Herrmann - Contribution for bug 295551 + * Jesper Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.internal.compiler.impl; @@ -103,6 +105,7 @@ public class CompilerOptions { public static final String OPTION_TaskPriorities = "org.eclipse.jdt.core.compiler.taskPriorities"; //$NON-NLS-1$ public static final String OPTION_TaskCaseSensitive = "org.eclipse.jdt.core.compiler.taskCaseSensitive"; //$NON-NLS-1$ public static final String OPTION_InlineJsr = "org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode"; //$NON-NLS-1$ + public static final String OPTION_ShareCommonFinallyBlocks = "org.eclipse.jdt.core.compiler.codegen.shareCommonFinallyBlocks"; //$NON-NLS-1$ public static final String OPTION_ReportNullReference = "org.eclipse.jdt.core.compiler.problem.nullReference"; //$NON-NLS-1$ public static final String OPTION_ReportPotentialNullReference = "org.eclipse.jdt.core.compiler.problem.potentialNullReference"; //$NON-NLS-1$ public static final String OPTION_ReportRedundantNullCheck = "org.eclipse.jdt.core.compiler.problem.redundantNullCheck"; //$NON-NLS-1$ @@ -337,6 +340,8 @@ public class CompilerOptions { public boolean reportMissingJavadocCommentsOverriding; /** Indicate whether the JSR bytecode should be inlined to avoid its presence in classfile */ public boolean inlineJsrBytecode; + /** Indicate whether common escaping finally blocks should be shared */ + public boolean shareCommonFinallyBlocks; /** Indicate if @SuppressWarning annotations are activated */ public boolean suppressWarnings; /** Indicate if @SuppressWarning annotations should also suppress optional errors */ @@ -956,6 +961,7 @@ public class CompilerOptions { optionsMap.put(OPTION_ReportSpecialParameterHidingField, this.reportSpecialParameterHidingField ? ENABLED : DISABLED); optionsMap.put(OPTION_MaxProblemPerUnit, String.valueOf(this.maxProblemsPerUnit)); optionsMap.put(OPTION_InlineJsr, this.inlineJsrBytecode ? ENABLED : DISABLED); + optionsMap.put(OPTION_ShareCommonFinallyBlocks, this.shareCommonFinallyBlocks ? ENABLED : DISABLED); optionsMap.put(OPTION_ReportNullReference, getSeverityString(NullReference)); optionsMap.put(OPTION_ReportPotentialNullReference, getSeverityString(PotentialNullReference)); optionsMap.put(OPTION_ReportRedundantNullCheck, getSeverityString(RedundantNullCheck)); @@ -1089,8 +1095,9 @@ public class CompilerOptions { this.reportMissingJavadocCommentsVisibility = ClassFileConstants.AccPublic; this.reportMissingJavadocCommentsOverriding = false; - // JSR bytecode inlining + // JSR bytecode inlining and sharing this.inlineJsrBytecode = false; + this.shareCommonFinallyBlocks = false; // javadoc comment support this.docCommentSupport = false; @@ -1315,6 +1322,13 @@ public class CompilerOptions { } } } + if ((optionValue = optionsMap.get(OPTION_ShareCommonFinallyBlocks)) != null) { + if (ENABLED.equals(optionValue)) { + this.shareCommonFinallyBlocks = true; + } else if (DISABLED.equals(optionValue)) { + this.shareCommonFinallyBlocks = false; + } + } if ((optionValue = optionsMap.get(OPTION_SuppressWarnings)) != null) { if (ENABLED.equals(optionValue)) { this.suppressWarnings = true; @@ -1586,6 +1600,7 @@ public class CompilerOptions { buf.append("\n\t- report unused parameter include doc comment reference : ").append(this.reportUnusedParameterIncludeDocCommentReference ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- report constructor/setter parameter hiding existing field : ").append(this.reportSpecialParameterHidingField ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- inline JSR bytecode : ").append(this.inlineJsrBytecode ? ENABLED : DISABLED); //$NON-NLS-1$ + buf.append("\n\t- share common finally blocks : ").append(this.shareCommonFinallyBlocks ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- report unavoidable generic type problems : ").append(this.reportUnavoidableGenericTypeProblems ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- unsafe type operation: ").append(getSeverityString(UncheckedTypeOperation)); //$NON-NLS-1$ buf.append("\n\t- unsafe raw type: ").append(getSeverityString(RawTypeReference)); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java index f987d0f758..711aecb267 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.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 Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code *******************************************************************************/ package org.eclipse.jdt.internal.formatter; @@ -339,6 +341,7 @@ public class DefaultCodeFormatter extends CodeFormatter { optionsMap.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); optionsMap.put(CompilerOptions.OPTION_MaxProblemPerUnit, String.valueOf(100)); optionsMap.put(CompilerOptions.OPTION_InlineJsr, CompilerOptions.DISABLED); + optionsMap.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.DISABLED); optionsMap.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.IGNORE); optionsMap.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.IGNORE); this.defaultCompilerOptions = optionsMap; |