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 190659 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 4
patch.txt (text/plain), 16.89 KB, created by
Srikanth Sankaran
on 2011-03-08 09:43:18 EST
(
hide
)
Description:
Patch - Part 4
Filename:
MIME Type:
Creator:
Srikanth Sankaran
Created:
2011-03-08 09:43:18 EST
Size:
16.89 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.8 >diff -u -r1.116.2.8 TryStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 5 Mar 2011 18:12:56 -0000 1.116.2.8 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java 8 Mar 2011 14:36:04 -0000 >@@ -27,6 +27,8 @@ > > 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_RETURN_VALUE_NAME = " returnValue".toCharArray(); //$NON-NLS-1$ > > private static LocalDeclaration [] NO_RESOURCES = new LocalDeclaration[0]; >@@ -69,6 +71,9 @@ > int preTryInitStateIndex = -1; > int naturalExitMergeInitStateIndex = -1; > int[] catchExitInitStateIndexes; >+ private LocalVariableBinding primaryExceptionVariable; >+ private LocalVariableBinding temporaryThrowableVariable; >+ private ExceptionLabel[] resourceBlockLabels; > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { > >@@ -85,6 +90,12 @@ > if (this.anyExceptionVariable != null) { > this.anyExceptionVariable.useFlag = LocalVariableBinding.USED; > } >+ if (this.primaryExceptionVariable != null) { >+ this.primaryExceptionVariable.useFlag = LocalVariableBinding.USED; >+ } >+ if (this.temporaryThrowableVariable != null) { >+ this.temporaryThrowableVariable.useFlag = LocalVariableBinding.USED; >+ } > if (this.returnAddressVariable != null) { // TODO (philippe) if subroutine is escaping, unused > this.returnAddressVariable.useFlag = LocalVariableBinding.USED; > } >@@ -106,6 +117,7 @@ > > for (int i = 0, max = this.resources.length; i < max; i++) { > flowInfo = this.resources[i].analyseCode(currentScope, handlingContext, flowInfo.copy()); >+ this.resources[i].binding.useFlag = LocalVariableBinding.USED; // Is implicitly used anyways. > TypeBinding type = this.resources[i].binding.type; > if (type != null && type.isValidBinding()) { > ReferenceBinding binding = (ReferenceBinding) type; >@@ -229,6 +241,7 @@ > > for (int i = 0, max = this.resources.length; i < max; i++) { > flowInfo = this.resources[i].analyseCode(currentScope, handlingContext, flowInfo.copy()); >+ this.resources[i].binding.useFlag = LocalVariableBinding.USED; // Is implicitly used anyways. > TypeBinding type = this.resources[i].binding.type; > if (type != null && type.isValidBinding()) { > ReferenceBinding binding = (ReferenceBinding) type; >@@ -425,7 +438,73 @@ > // generate the try block > try { > this.declaredExceptionLabels = exceptionLabels; >+ int resourceCount = this.resources.length; >+ if (resourceCount > 0) { >+ this.resourceBlockLabels = 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); >+ for (int i = 0; i <= resourceCount; i++) { >+ this.resourceBlockLabels[i] = new ExceptionLabel(codeStream, this.scope.getJavaLangThrowable()); >+ this.resourceBlockLabels[i].placeStart(); >+ if (i < resourceCount) { >+ this.resources[i].generateCode(this.scope, codeStream); >+ } >+ } >+ } > this.tryBlock.generateCode(this.scope, codeStream); >+ if (resourceCount > 0) { >+ for (int i = resourceCount; i >= 0; i--) { >+ BranchLabel exitLabel = new BranchLabel(codeStream); >+ this.resourceBlockLabels[i].placeEnd(); >+ >+ LocalVariableBinding localVariable = i > 0 ? this.resources[i-1].binding : null; >+ if ((this.bits & ASTNode.IsTryBlockExiting) == 0) { >+ if (i > 0) { >+ codeStream.load(localVariable); >+ codeStream.ifnull(exitLabel); >+ codeStream.load(localVariable); >+ codeStream.invokeAutoCloseableClose(localVariable.type); >+ } >+ 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(); >+ if (i > 0) { >+ // inline resource close here rather than bracketing the current catch block with a try region. >+ BranchLabel postCloseLabel = new BranchLabel(codeStream); >+ codeStream.load(localVariable); >+ codeStream.ifnull(postCloseLabel); >+ codeStream.load(localVariable); >+ codeStream.invokeAutoCloseableClose(localVariable.type); >+ codeStream.removeVariable(localVariable); >+ postCloseLabel.place(); >+ } >+ codeStream.load(this.primaryExceptionVariable); >+ codeStream.athrow(); >+ exitLabel.place(); >+ } >+ codeStream.removeVariable(this.primaryExceptionVariable); >+ codeStream.removeVariable(this.temporaryThrowableVariable); >+ } > } finally { > this.declaredExceptionLabels = null; > } >@@ -806,11 +885,21 @@ > this.scope = new BlockScope(upperScope); > > BlockScope finallyScope = null; >- >- // resolve all resources and inject them into separate scopes >- BlockScope localScope = new BlockScope(this.scope); >- for (int i = 0, max = this.resources.length; i < max; i++) { >- this.resources[i].resolve(localScope); >+ BlockScope resourceManagementScope = null; >+ int resourceCount = this.resources.length; >+ if (resourceCount > 0) { >+ resourceManagementScope = new BlockScope(this.scope); >+ this.primaryExceptionVariable = >+ 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 >+ } >+ for (int i = 0; i < resourceCount; i++) { >+ this.resources[i].resolve(resourceManagementScope); > LocalVariableBinding localVariableBinding = this.resources[i].binding; > if (localVariableBinding != null && localVariableBinding.isValidBinding()) { > localVariableBinding.modifiers |= ClassFileConstants.AccFinal; >@@ -826,9 +915,8 @@ > localVariableBinding.type = new ProblemReferenceBinding(CharOperation.splitOn('.', resourceType.shortReadableName()), null, ProblemReasons.InvalidTypeForAutoManagedResource); > } > } >- localScope = new BlockScope(localScope, 1); > } >- BlockScope tryScope = localScope; >+ BlockScope tryScope = new BlockScope(resourceManagementScope != null ? resourceManagementScope : this.scope); > > if (this.finallyBlock != null) { > if (this.finallyBlock.isEmptyBlock()) { >@@ -875,15 +963,8 @@ > this.finallyBlock.resolveUsing(finallyScope); > // force the finally scope to have variable positions shifted after its try scope and catch ones > int shiftScopesLength = this.catchArguments == null ? 1 : this.catchArguments.length + 1; >- shiftScopesLength += this.resources.length; > finallyScope.shiftScopes = new BlockScope[shiftScopesLength]; >- for (int i = 0, max = this.resources.length; i < max; i++) { >- LocalVariableBinding localVariableBinding = this.resources[i].binding; >- if (localVariableBinding != null && localVariableBinding.isValidBinding()) { >- finallyScope.shiftScopes[i] = localVariableBinding.declaringScope; >- } >- } >- finallyScope.shiftScopes[this.resources.length] = tryScope; >+ finallyScope.shiftScopes[0] = tryScope; > } > } > this.tryBlock.resolveUsing(tryScope); >Index: compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java,v >retrieving revision 1.180.2.1 >diff -u -r1.180.2.1 CodeStream.java >--- compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java 21 Jan 2011 02:29:25 -0000 1.180.2.1 >+++ compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java 8 Mar 2011 14:36:09 -0000 >@@ -4030,6 +4030,26 @@ > ConstantPool.ITERATOR_SIGNATURE); > } > >+public void invokeAutoCloseableClose(TypeBinding resourceType) { >+ // invokevirtual/interface: <resourceType>.close() >+ invoke( >+ resourceType.isInterface() ? Opcodes.OPC_invokeinterface : Opcodes.OPC_invokevirtual, >+ 1, // receiverAndArgsSize >+ 0, // returnTypeSize >+ resourceType.constantPoolName(), >+ ConstantPool.Close, >+ ConstantPool.CloseSignature); >+} >+ >+public void invokeThrowableAddSuppressed() { >+ invoke(Opcodes.OPC_invokevirtual, >+ 2, // receiverAndArgsSize >+ 0, // returnTypeSize >+ ConstantPool.JavaLangThrowableConstantPoolName, >+ ConstantPool.AddSuppressed, >+ ConstantPool.AddSuppressedSignature); >+} >+ > public void invokeJavaLangAssertionErrorConstructor(int typeBindingID) { > // invokespecial: java.lang.AssertionError.<init>(typeBindingID)V > int receiverAndArgsSize; >Index: compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java,v >retrieving revision 1.61.8.4 >diff -u -r1.61.8.4 ConstantPool.java >--- compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java 2 Mar 2011 11:56:58 -0000 1.61.8.4 >+++ compiler/org/eclipse/jdt/internal/compiler/codegen/ConstantPool.java 8 Mar 2011 14:36:10 -0000 >@@ -76,6 +76,7 @@ > public static final char[] DefaultConstructorSignature = "()V".toCharArray(); //$NON-NLS-1$ > public static final char[] ClinitSignature = DefaultConstructorSignature; > public static final char[] Close = "close".toCharArray(); //$NON-NLS-1$ >+ public static final char[] CloseSignature = "()V".toCharArray(); //$NON-NLS-1$ > public static final char[] DesiredAssertionStatus = "desiredAssertionStatus".toCharArray(); //$NON-NLS-1$ > public static final char[] DesiredAssertionStatusSignature = "()Z".toCharArray(); //$NON-NLS-1$ > public static final char[] DoubleConstrSignature = "(D)V".toCharArray(); //$NON-NLS-1$ >@@ -256,6 +257,8 @@ > public static final char[] HashCodeSignature = "()I".toCharArray(); //$NON-NLS-1$; > public static final char[] Equals = "equals".toCharArray(); //$NON-NLS-1$ > public static final char[] EqualsSignature = "(Ljava/lang/Object;)Z".toCharArray(); //$NON-NLS-1$; >+ public static final char[] AddSuppressed = "addSuppressed".toCharArray(); //$NON-NLS-1$; >+ public static final char[] AddSuppressedSignature = "(Ljava/lang/Throwable;)V".toCharArray(); //$NON-NLS-1$ > /** > * ConstantPool constructor comment. > */ >#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.9 >diff -u -r1.1.2.9 TryWithResourcesStatementTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java 2 Mar 2011 11:56:54 -0000 1.1.2.9 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java 8 Mar 2011 14:36:14 -0000 >@@ -147,18 +147,24 @@ > } > //check that try statement can be empty > public void test006() { >- this.runConformTest( >+ this.runNegativeTest( // cannot be a conform test as this triggers an AIOOB. > new String[] { > "X.java", > "import java.io.*;\n" + > "public class X {\n" + > " public static void main(String[] args) throws IOException {\n" + > " try (Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" + >- " }\n" + >+ " } catch(Zork z) {" + >+ " }\n" + > " }\n" + > "}", > }, >- ""); >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " } catch(Zork z) { }\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); > } > //check that resources are implicitly final but they can be explicitly final > public void test007() { >@@ -966,6 +972,78 @@ > "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + > "----------\n"); > } >+public void _test027() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X implements AutoCloseable {\n" + >+ " public static void main(String [] args) throws Exception {\n" + >+ " try (X x = new X(); Y y = new Y()) {\n" + >+ " System.out.println(\"Body\");\n" + >+ " throw new Exception(\"Body\");\n" + >+ " } catch (Exception e) {\n" + >+ " e.printStackTrace(System.out);\n" + >+ " Throwable [] suppressed = e.getSuppressed();\n" + >+ " if (suppressed.length == 0) System.out.println(\"Nothing suppressed\");\n" + >+ " for (int i = 0; i < suppressed.length; i++) {\n" + >+ " System.out.println(\"Suppressed:\" + suppressed[i]);\n" + >+ " }\n" + >+ " } finally {\n" + >+ " int finallyVar = 10;\n" + >+ " System.out.println(finallyVar);\n" + >+ " }\n" + >+ " }\n" + >+ " public X() {\n" + >+ " System.out.println(\"X CTOR\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"X Close\");\n" + >+ " throw new Exception(\"X Close\");\n" + >+ " }\n" + >+ "}\n" + >+ "\n" + >+ "class Y implements AutoCloseable {\n" + >+ " public Y() {\n" + >+ " System.out.println(\"Y CTOR\");\n" + >+ " }\n" + >+ " public void close() throws Exception {\n" + >+ " System.out.println(\"Y Close\");\n" + >+ " throw new Exception(\"Y Close\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 37)\n" + >+ " class XException extends Exception {}\n" + >+ " ^^^^^^^^^^\n" + >+ "The serializable class XException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 38)\n" + >+ " class XXException extends Exception {}\n" + >+ " ^^^^^^^^^^^\n" + >+ "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 39)\n" + >+ " class YException extends Exception {}\n" + >+ " ^^^^^^^^^^\n" + >+ "The serializable class YException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 40)\n" + >+ " class YYException extends Exception {}\n" + >+ " ^^^^^^^^^^^\n" + >+ "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 41)\n" + >+ " class ZException extends Exception {}\n" + >+ " ^^^^^^^^^^\n" + >+ "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 42)\n" + >+ " class ZZException extends Exception {}\n" + >+ " ^^^^^^^^^^^\n" + >+ "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + >+ "----------\n"); >+} > 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