Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 190744 Details for
Bug 338402
[1.7][compiler][enh] Open issues in try with resources implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch - Part 5
patch.txt (text/plain), 15.98 KB, created by
Srikanth Sankaran
on 2011-03-09 05:10:09 EST
(
hide
)
Description:
Patch - Part 5
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-03-09 05:10:09 EST
Size:
15.98 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java,v >retrieving revision 1.116.2.10 >diff -u -r1.116.2.10 TryStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 8 Mar 2011 23:36:12 -0000 1.116.2.10 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 9 Mar 2011 10:04:42 -0000 >@@ -28,7 +28,7 @@ > static final char[] SECRET_RETURN_ADDRESS_NAME = " returnAddress".toCharArray(); //$NON-NLS-1$ > static final char[] SECRET_ANY_HANDLER_NAME = " anyExceptionHandler".toCharArray(); //$NON-NLS-1$ > static final char[] SECRET_PRIMARY_EXCEPTION_VARIABLE_NAME = " primaryException".toCharArray(); //$NON-NLS-1$ >- static final char[] SECRET_TEMPORARY_THROWABLE_VARIABLE_NAME = " temporaryThrowable".toCharArray(); //$NON-NLS-1$; >+ static final char[] SECRET_CAUGHT_THROWABLE_VARIABLE_NAME = " caughtThrowable".toCharArray(); //$NON-NLS-1$; > static final char[] SECRET_RETURN_VALUE_NAME = " returnValue".toCharArray(); //$NON-NLS-1$ > > private static LocalDeclaration [] NO_RESOURCES = new LocalDeclaration[0]; >@@ -72,8 +72,8 @@ > int naturalExitMergeInitStateIndex = -1; > int[] catchExitInitStateIndexes; > private LocalVariableBinding primaryExceptionVariable; >- private LocalVariableBinding temporaryThrowableVariable; >- private ExceptionLabel[] resourceBlockLabels; >+ private LocalVariableBinding caughtThrowableVariable; >+ private ExceptionLabel[] resourceExceptionLabels; > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { > >@@ -93,8 +93,8 @@ > if (this.primaryExceptionVariable != null) { > this.primaryExceptionVariable.useFlag = LocalVariableBinding.USED; > } >- if (this.temporaryThrowableVariable != null) { >- this.temporaryThrowableVariable.useFlag = LocalVariableBinding.USED; >+ if (this.caughtThrowableVariable != null) { >+ this.caughtThrowableVariable.useFlag = LocalVariableBinding.USED; > } > if (this.returnAddressVariable != null) { // TODO (philippe) if subroutine is escaping, unused > this.returnAddressVariable.useFlag = LocalVariableBinding.USED; >@@ -440,16 +440,16 @@ > this.declaredExceptionLabels = exceptionLabels; > int resourceCount = this.resources.length; > if (resourceCount > 0) { >- this.resourceBlockLabels = new ExceptionLabel[resourceCount + 1]; >+ this.resourceExceptionLabels = new ExceptionLabel[resourceCount + 1]; > codeStream.aconst_null(); > codeStream.store(this.primaryExceptionVariable, false /* value not required */); > codeStream.addVariable(this.primaryExceptionVariable); > codeStream.aconst_null(); >- codeStream.store(this.temporaryThrowableVariable, false /* value not required */); >- codeStream.addVariable(this.temporaryThrowableVariable); >+ codeStream.store(this.caughtThrowableVariable, false /* value not required */); >+ codeStream.addVariable(this.caughtThrowableVariable); > for (int i = 0; i <= resourceCount; i++) { >- this.resourceBlockLabels[i] = new ExceptionLabel(codeStream, this.scope.getJavaLangThrowable()); >- this.resourceBlockLabels[i].placeStart(); >+ this.resourceExceptionLabels[i] = new ExceptionLabel(codeStream, this.scope.getJavaLangThrowable()); >+ this.resourceExceptionLabels[i].placeStart(); > if (i < resourceCount) { > this.resources[i].generateCode(this.scope, codeStream); > } >@@ -459,7 +459,7 @@ > if (resourceCount > 0) { > for (int i = resourceCount; i >= 0; i--) { > BranchLabel exitLabel = new BranchLabel(codeStream); >- this.resourceBlockLabels[i].placeEnd(); >+ this.resourceExceptionLabels[i].placeEnd(); > > LocalVariableBinding localVariable = i > 0 ? this.resources[i-1].binding : null; > if ((this.bits & ASTNode.IsTryBlockExiting) == 0) { >@@ -472,22 +472,28 @@ > codeStream.goto_(exitLabel); > } > codeStream.pushExceptionOnStack(this.scope.getJavaLangThrowable()); >- this.resourceBlockLabels[i].place(); >- BranchLabel elseLabel = new BranchLabel(codeStream), postElseLabel = new BranchLabel(codeStream); >- codeStream.store(this.temporaryThrowableVariable, false); >- codeStream.load(this.primaryExceptionVariable); >- codeStream.ifnonnull(elseLabel); >- codeStream.load(this.temporaryThrowableVariable); >- codeStream.store(this.primaryExceptionVariable, false); >- codeStream.goto_(postElseLabel); >- elseLabel.place(); >- codeStream.load(this.primaryExceptionVariable); >- codeStream.load(this.temporaryThrowableVariable); >- codeStream.if_acmpeq(postElseLabel); >- codeStream.load(this.primaryExceptionVariable); >- codeStream.load(this.temporaryThrowableVariable); >- codeStream.invokeThrowableAddSuppressed(); >- postElseLabel.place(); >+ this.resourceExceptionLabels[i].place(); >+ if (i == resourceCount) { >+ // inner most try's catch/finally can be a lot simpler. >+ codeStream.store(this.primaryExceptionVariable, false); >+ // fall through, invoke close() and re-throw. >+ } else { >+ BranchLabel elseLabel = new BranchLabel(codeStream), postElseLabel = new BranchLabel(codeStream); >+ codeStream.store(this.caughtThrowableVariable, false); >+ codeStream.load(this.primaryExceptionVariable); >+ codeStream.ifnonnull(elseLabel); >+ codeStream.load(this.caughtThrowableVariable); >+ codeStream.store(this.primaryExceptionVariable, false); >+ codeStream.goto_(postElseLabel); >+ elseLabel.place(); >+ codeStream.load(this.primaryExceptionVariable); >+ codeStream.load(this.caughtThrowableVariable); >+ codeStream.if_acmpeq(postElseLabel); >+ codeStream.load(this.primaryExceptionVariable); >+ codeStream.load(this.caughtThrowableVariable); >+ codeStream.invokeThrowableAddSuppressed(); >+ postElseLabel.place(); >+ } > if (i > 0) { > // inline resource close here rather than bracketing the current catch block with a try region. > BranchLabel postCloseLabel = new BranchLabel(codeStream); >@@ -503,7 +509,7 @@ > exitLabel.place(); > } > codeStream.removeVariable(this.primaryExceptionVariable); >- codeStream.removeVariable(this.temporaryThrowableVariable); >+ codeStream.removeVariable(this.caughtThrowableVariable); > } > } finally { > this.declaredExceptionLabels = null; >@@ -755,6 +761,25 @@ > */ > public boolean generateSubRoutineInvocation(BlockScope currentScope, CodeStream codeStream, Object targetLocation, int stateIndex, LocalVariableBinding secretLocal) { > >+ int resourceCount = this.resources.length; >+ if (resourceCount > 0) { >+ for (int i = resourceCount; i > 0; --i) { >+ // disarm the handlers and take care of resource closure. >+ this.resourceExceptionLabels[i].placeEnd(); >+ LocalVariableBinding localVariable = this.resources[i-1].binding; >+ BranchLabel exitLabel = new BranchLabel(codeStream); >+ codeStream.load(localVariable); >+ codeStream.ifnull(exitLabel); >+ codeStream.load(localVariable); >+ codeStream.invokeAutoCloseableClose(localVariable.type); >+ exitLabel.place(); >+ } >+ // restore handlers >+ for (int i = resourceCount; i > 0; --i) { >+ this.resourceExceptionLabels[i].placeStart(); >+ } >+ } >+ > boolean isStackMapFrameCodeStream = codeStream instanceof StackMapFrameCodeStream; > int finallyMode = finallyMode(); > switch(finallyMode) { >@@ -893,10 +918,10 @@ > new LocalVariableBinding(TryStatement.SECRET_PRIMARY_EXCEPTION_VARIABLE_NAME, this.scope.getJavaLangThrowable(), ClassFileConstants.AccDefault, false); > resourceManagementScope.addLocalVariable(this.primaryExceptionVariable); > this.primaryExceptionVariable.setConstant(Constant.NotAConstant); // not inlinable >- this.temporaryThrowableVariable = >- new LocalVariableBinding(TryStatement.SECRET_TEMPORARY_THROWABLE_VARIABLE_NAME, this.scope.getJavaLangThrowable(), ClassFileConstants.AccDefault, false); >- resourceManagementScope.addLocalVariable(this.temporaryThrowableVariable); >- this.temporaryThrowableVariable.setConstant(Constant.NotAConstant); // not inlinable >+ this.caughtThrowableVariable = >+ new LocalVariableBinding(TryStatement.SECRET_CAUGHT_THROWABLE_VARIABLE_NAME, this.scope.getJavaLangThrowable(), ClassFileConstants.AccDefault, false); >+ resourceManagementScope.addLocalVariable(this.caughtThrowableVariable); >+ this.caughtThrowableVariable.setConstant(Constant.NotAConstant); // not inlinable > } > for (int i = 0; i < resourceCount; i++) { > this.resources[i].resolve(resourceManagementScope); >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Attic/TryWithResourcesStatementTest.java,v >retrieving revision 1.1.2.11 >diff -u -r1.1.2.11 TryWithResourcesStatementTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java 9 Mar 2011 05:41:37 -0000 1.1.2.11 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java 9 Mar 2011 10:04:52 -0000 >@@ -1079,6 +1079,214 @@ > }, > "Got IO exception"); > } >+public void test030() { // test return + resources >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X implements AutoCloseable {\n" + >+ " public static void main(String [] args) throws Exception { \n" + >+ " final boolean getOut = true;\n" + >+ " System.out.println(\"Main\");\n" + >+ " try (X x1 = new X(); X x2 = new X()) {\n" + >+ " System.out.println(\"Outer Try\");\n" + >+ " while (true) {\n" + >+ " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + >+ " System.out.println(\"Middle Try\");\n" + >+ " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + >+ " System.out.println(\"Inner Try\");\n" + >+ " if (getOut) \n" + >+ " return;\n" + >+ " else\n" + >+ " break;\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " System.out.println(\"Out of while\");\n" + >+ " }\n" + >+ " }\n" + >+ " public X() {\n" + >+ " System.out.println(\"X::X\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"X::~X\");\n" + >+ " }\n" + >+ "}\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public Y() {\n" + >+ " System.out.println(\"Y::Y\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Y::~Y\");\n" + >+ " }\n" + >+ "}\n" + >+ "class Z implements AutoCloseable {\n" + >+ " public Z() {\n" + >+ " System.out.println(\"Z::Z\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Z::~Z\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "Main\n" + >+ "X::X\n" + >+ "X::X\n" + >+ "Outer Try\n" + >+ "Y::Y\n" + >+ "Y::Y\n" + >+ "Middle Try\n" + >+ "Z::Z\n" + >+ "Z::Z\n" + >+ "Inner Try\n" + >+ "Z::~Z\n" + >+ "Z::~Z\n" + >+ "Y::~Y\n" + >+ "Y::~Y\n" + >+ "X::~X\n" + >+ "X::~X"); >+} >+public void test031() { // test break + resources >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X implements AutoCloseable {\n" + >+ " public static void main(String [] args) throws Exception { \n" + >+ " final boolean getOut = false;\n" + >+ " System.out.println(\"Main\");\n" + >+ " try (X x1 = new X(); X x2 = new X()) {\n" + >+ " System.out.println(\"Outer Try\");\n" + >+ " while (true) {\n" + >+ " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + >+ " System.out.println(\"Middle Try\");\n" + >+ " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + >+ " System.out.println(\"Inner Try\");\n" + >+ " if (getOut) \n" + >+ " return;\n" + >+ " else\n" + >+ " break;\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ " System.out.println(\"Out of while\");\n" + >+ " }\n" + >+ " }\n" + >+ " public X() {\n" + >+ " System.out.println(\"X::X\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"X::~X\");\n" + >+ " }\n" + >+ "}\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public Y() {\n" + >+ " System.out.println(\"Y::Y\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Y::~Y\");\n" + >+ " }\n" + >+ "}\n" + >+ "class Z implements AutoCloseable {\n" + >+ " public Z() {\n" + >+ " System.out.println(\"Z::Z\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Z::~Z\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "Main\n" + >+ "X::X\n" + >+ "X::X\n" + >+ "Outer Try\n" + >+ "Y::Y\n" + >+ "Y::Y\n" + >+ "Middle Try\n" + >+ "Z::Z\n" + >+ "Z::Z\n" + >+ "Inner Try\n" + >+ "Z::~Z\n" + >+ "Z::~Z\n" + >+ "Y::~Y\n" + >+ "Y::~Y\n" + >+ "Out of while\n" + >+ "X::~X\n" + >+ "X::~X"); >+} >+public void test032() { // test continue + resources >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X implements AutoCloseable {\n" + >+ " public static void main(String [] args) throws Exception { \n" + >+ " final boolean getOut = false;\n" + >+ " System.out.println(\"Main\");\n" + >+ " try (X x1 = new X(); X x2 = new X()) {\n" + >+ " System.out.println(\"Outer Try\");\n" + >+ " boolean more = true;\n" + >+ " while (more) {\n" + >+ " try (Y y1 = new Y(); Y y2 = new Y()) {\n" + >+ " System.out.println(\"Middle Try\");\n" + >+ " try (Z z1 = new Z(); Z z2 = new Z()) {\n" + >+ " System.out.println(\"Inner Try\");\n" + >+ " more = false;\n" + >+ " continue;\n" + >+ " } finally { \n" + >+ " System.out.println(\"Inner Finally\");\n" + >+ " }\n" + >+ " } finally {\n" + >+ " System.out.println(\"Middle Finally\");\n" + >+ " }\n" + >+ " }\n" + >+ " System.out.println(\"Out of while\");\n" + >+ " } finally {\n" + >+ " System.out.println(\"Outer Finally\");\n" + >+ " }\n" + >+ " }\n" + >+ " public X() {\n" + >+ " System.out.println(\"X::X\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"X::~X\");\n" + >+ " }\n" + >+ "}\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public Y() {\n" + >+ " System.out.println(\"Y::Y\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Y::~Y\");\n" + >+ " }\n" + >+ "}\n" + >+ "class Z implements AutoCloseable {\n" + >+ " public Z() {\n" + >+ " System.out.println(\"Z::Z\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Z::~Z\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "Main\n" + >+ "X::X\n" + >+ "X::X\n" + >+ "Outer Try\n" + >+ "Y::Y\n" + >+ "Y::Y\n" + >+ "Middle Try\n" + >+ "Z::Z\n" + >+ "Z::Z\n" + >+ "Inner Try\n" + >+ "Z::~Z\n" + >+ "Z::~Z\n" + >+ "Inner Finally\n" + >+ "Y::~Y\n" + >+ "Y::~Y\n" + >+ "Middle Finally\n" + >+ "Out of while\n" + >+ "X::~X\n" + >+ "X::~X\n" + >+ "Outer Finally"); >+} > public static Class testClass() { > return TryWithResourcesStatementTest.class; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 338402
:
190016
|
190034
|
190131
|
190659
| 190744 |
190751