diff options
author | Sasikanth Bharadwaj | 2018-04-05 06:58:58 +0000 |
---|---|---|
committer | Sasikanth Bharadwaj | 2018-04-05 10:03:54 +0000 |
commit | 6f556c76a69aeda176203bc132d4174f69e9ee9a (patch) | |
tree | 6486998cf93fb79493d544f4ccd98ce839cadb8b | |
parent | 3d360bac4bfccf56f0adb288d3a10d2394f3108c (diff) | |
download | eclipse.jdt.core-6f556c76a69aeda176203bc132d4174f69e9ee9a.tar.gz eclipse.jdt.core-6f556c76a69aeda176203bc132d4174f69e9ee9a.tar.xz eclipse.jdt.core-6f556c76a69aeda176203bc132d4174f69e9ee9a.zip |
Fixed Bug 533187: JDT generates incorrect code forI20180406-2000I20180405-2000
try-with-resources and synchronized construct
Change-Id: Icd13499f9bd98b4fb8b94f538902d54bdfa7283d
3 files changed, 89 insertions, 9 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java index b2c60346ed..2e7081a7c9 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StackMapAttributeTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2014 IBM Corporation and others. + * Copyright (c) 2006, 2018 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 @@ -7878,8 +7878,8 @@ public class StackMapAttributeTest extends AbstractRegressionTest { " 127 return\n" + " Exception Table:\n" + " [pc: 17, pc: 22] -> 51 when : any\n" + - " [pc: 32, pc: 38] -> 51 when : any\n" + - " [pc: 6, pc: 64] -> 64 when : any\n" + + " [pc: 6, pc: 32] -> 64 when : any\n" + + " [pc: 38, pc: 64] -> 64 when : any\n" + " [pc: 2, pc: 32] -> 98 when : java.io.IOException\n" + " [pc: 38, pc: 92] -> 98 when : java.io.IOException\n" + " [pc: 2, pc: 32] -> 112 when : any\n" + diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java index 802f002e10..5b3e7114e4 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2014 IBM Corporation and others. + * Copyright (c) 2011, 2018 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 @@ -4230,6 +4230,82 @@ public void test394780() { }, "computeclose"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=533187 +public void testBug533187() { + this.runConformTest( + true, + new String[] { + "Stuck.java", + "public class Stuck {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(snippet1());\n" + + " }\n" + + " public static String snippet1() {\n" + + " try {\n" + + " synchronized (String.class) {\n" + + " try (AutoCloseable scope = null) { \n" + + " return \"RETURN\";\n" + + " } catch (Throwable t) {\n" + + " return t.toString();\n" + + " }\n" + + " }\n" + + " } finally {\n" + + " raise();\n" + + " }\n" + + " }\n" + + " public static void raise() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}" + }, + null, + null, + null, + null, + "java.lang.RuntimeException\n" + + " at Stuck.raise(Stuck.java:19)\n" + + " at Stuck.snippet1(Stuck.java:15)\n" + + " at Stuck.main(Stuck.java:3)\n", + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=467230 +public void testBug467230() { + this.runConformTest( + true, + new String[] { + "Test.java", + "public class Test {\n" + + " static class C implements AutoCloseable {\n" + + " @Override\n" + + " public void close() {\n" + + " System.out.println(\"close\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try (C c = new C()) {\n" + + " return;\n" + + " } catch (Exception e) {\n" + + " System.out.println(\"catch\");\n" + + " } finally {\n" + + " f();\n" + + " }\n" + + " }\n" + + " private static void f() {\n" + + " System.out.println(\"finally\");\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}" + }, + null, + null, + null, + "close\n" + + "finally", + "java.lang.RuntimeException\n" + + " at Test.f(Test.java:19)\n" + + " at Test.main(Test.java:14)\n", + null); +} public static Class testClass() { return TryWithResourcesStatementTest.class; } 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 e10440ac6f..8514e86a83 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -452,6 +452,13 @@ public void enterDeclaredExceptionHandlers(CodeStream codeStream) { for (int i = 0, length = this.declaredExceptionLabels == null ? 0 : this.declaredExceptionLabels.length; i < length; i++) { this.declaredExceptionLabels[i].placeStart(); } + int resourceCount = this.resources.length; + if (resourceCount > 0 && this.resourceExceptionLabels != null) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 + // Reinstall handlers + for (int i = resourceCount; i >= 0; --i) { + this.resourceExceptionLabels[i].placeStart(); + } + } } @Override @@ -950,10 +957,7 @@ public boolean generateSubRoutineInvocation(BlockScope currentScope, CodeStream codeStream.recordPositionsFrom(invokeCloseStartPc, this.tryBlock.sourceEnd); exitLabel.place(); } - // Reinstall handlers - for (int i = resourceCount; i > 0; --i) { - this.resourceExceptionLabels[i].placeStart(); - } + this.resourceExceptionLabels[0].placeEnd(); // outermost should end here as well, will start again on enter } boolean isStackMapFrameCodeStream = codeStream instanceof StackMapFrameCodeStream; |