JDK-8065600 : 14.20.3: Allow certain variables as resources
Type:Sub-task
Component:specification
Sub-Component:language
Affected Version:7,8
Priority:P4
Status:Closed
Resolution:Fixed
Submitted:2014-11-20
Updated:2018-08-03
Resolved:2016-09-27
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
The currently proposed JLS changes:
JLS 6.1 changes:
The following sentence:
---
The 13 non-generic contexts are as follows:
---
is changed to:
---
The 14 non-generic contexts are as follows:
---
the consequent list of the non-generic contexts is augmented with:
---
14. In a qualified expression name in a VariableAccess expression (��14.20.3)
---
in the consequent paragraph, this sentence:
---
The eleventh non-generic context is a postfix expression, where a qualified ExpressionName such as C.x may include a TypeName C to denote static member access.
---
is changed to:
---
The eleventh and fourteenth non-generic contexts are a postfix expression and a VariableAccess expression, respectivelly, where a qualified ExpressionName such as C.x may include a TypeName C to denote static member access.
---
JLS 6.3 changes:
The following text:
---
The scope of a variable declared in the ResourceSpecification
---
is augmented like:
---
The scope of a variable declared explicitly or implicitly in the ResourceSpecification
---
JLS 6.5.1 changes:
The following test:
---
As the left-hand operand of an assignment operator (��15.26)
---
is changes into:
---
As a VariableAccess (��14.20.3)
---
JLS 14.20.3 changes:
The following grammar production:
---
Resource:
{VariableModifier} UnannType VariableDeclaratorId = Expression
---
is enhanced like this:
---
Resource:
{VariableModifier} UnannType VariableDeclaratorId = Expression
VariableAccess
VariableAccess:
ExpressionName
FieldAccess
---
The following assertion is inserted between 'The scope and shadowing of a variable declared in a resource specification is specified in ��6.3 and ��6.4. ' and 'Resources are initialized in left-to-right order. ...':
---
An operand to try-with-resources may be a VariableAccess expression, which is an expression name (6.5.6) or a field access expression (15.11). The name or expression must denote a final or effectivelly final variable of type AutoCloseable which is definitely assigned before the t-w-r; otherwise, a compile-time error occurs.
---
JLS 14.20.3.1. changes:
The following is inserted between the first and the second paragraph:
---
If the basic try-with-resources statement is of the form:
try (VariableAccess ...)
Block
it is first converted to a resource variable by the following translation:
try (Type #r = VariableAccess ...) {
Block
}
Where Type is the type of the variable denoted by VariableAccess and #r is an automatically generated identifier that is distinct from any other identifiers (automatically generated or otherwise) that are in scope at the point where the try-with-resources statement occurs. The try-with-resources statement is then converted using the following approach.
---
The consequent paragraph is slightly rephrased from:
---
The meaning of a basic try-with-resources statement:
---
to:
---
The meaning of a basic try-with-resources statement of form:
---
JLS 15.26 changes:
---
LeftHandSide:
ExpressionName
FieldAccess
ArrayAccess
---
into:
---
LeftHandSide:
VariableAccess
ArrayAccess
---