Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 402673 - [1.8][dom ast] ASTs < JLS8 must not create new node types
Summary: [1.8][dom ast] ASTs < JLS8 must not create new node types
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-07 11:38 EST by Markus Keller CLA
Modified: 2013-03-15 06:43 EDT (History)
1 user (show)

See Also:
srikanth_sankaran: review+


Attachments
Proposed Patch (9.00 KB, patch)
2013-03-15 03:04 EDT, Manoj N Palat CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2013-03-07 11:38:06 EST
ASTs before JLS8 must not try to create nodes that are only allowed in JLS8.

Hint: Open a call hierarchy on ASTNode#unsupportedIn2_3_4() and make sure all accesses are properly protected. You may want to set "Search Scope > Project" in the view menu.


E.g. LambdaExpression nodes:

package jsr335;
public class RunnableTest {
	Runnable r = () -> System.out.println("hi");
}

java.lang.UnsupportedOperationException: Operation only supported in JLS8 and later AST
	at org.eclipse.jdt.core.dom.ASTNode.unsupportedIn2_3_4(ASTNode.java:1906)
	at org.eclipse.jdt.core.dom.LambdaExpression.<init>(LambdaExpression.java:127)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2144)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1724)
	at org.eclipse.jdt.core.dom.ASTConverter.convertToVariableDeclarationFragment(ASTConverter.java:3137)
	at org.eclipse.jdt.core.dom.ASTConverter.convertToFieldDeclaration(ASTConverter.java:3026)
	at org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleFieldDeclaration(ASTConverter.java:417)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:183)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2809)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1329)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:295)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1212)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:812)
Comment 1 Srikanth Sankaran CLA 2013-03-07 18:28:45 EST
Please follow up asap. TIA.

I don't see a check for AST level in org.eclipse.jdt.core.dom.ASTConverter.convert(LambdaExpression). We should tag
the tree as being MALFORMED for lower JLS levels.
Comment 2 Srikanth Sankaran CLA 2013-03-11 02:24:05 EDT
For LambdaExpressions, figuring out the "containing context" node to flag as 
being malformed has some challenges. As is written, convert(Expression) does 
not get to know the parent node. 

(1) Now this method could be refactored to receive a parent node, but that 
looks like an overkill for basically tagging the AST as being broken. (there 
are many callers (70+ - while lambda expressions can legally occur in only a
few of them,  they can syntactically-legally occur in all of them)

(2) ASTVisitor as is, does not have a notion of last visited node - so it can't 
also be used without extensive changes to find the parent node.

I see two quick solutions:

(1) A coarse grained flagging approach:

where 

(a) convert(LE) would return null for level < JLS8 and
(b) flag the closest method/type as being MALFORMED.

(2) convert(LE) could return a NullLiteral node that is flagged as being
MALFORMED.

(2) is a bit unorthodox and so we are proceeding with (1) - the coarse
grained flagging approach.

Markus, any reason this won't be sufficient for clients ? The compiler 
would have generated a suitable IProblem anyway
Comment 3 Manoj N Palat CLA 2013-03-14 23:39:22 EDT
(In reply to comment #2)

I see two quick solutions:

(1)
> A coarse grained flagging approach:

where 

(a) convert(LE) would return
> null for level < JLS8 and
(b) flag the closest method/type as being
> MALFORMED.

(2) convert(LE) could return a NullLiteral node that is flagged
> as being
MALFORMED.

(2) is a bit unorthodox and so we are proceeding with
> (1) - the coarse
grained flagging approach.

The approach 1 was tried, but found to affect multiple places by throwing NPE. So we will be going ahead with (2) and returning a NullLiteral (with source positions) for AST < JLS8.
Comment 4 Srikanth Sankaran CLA 2013-03-14 23:54:16 EDT
(In reply to comment #3)

> The approach 1 was tried, but found to affect multiple places by throwing
> NPE. So we will be going ahead with (2) and returning a NullLiteral (with
> source positions) for AST < JLS8.

Please tag the closest method/type as being malformed - in addition for good
measure also tag the manufactured NullLiteral as being malformed.
Comment 5 Srikanth Sankaran CLA 2013-03-15 00:37:27 EDT
(In reply to comment #3)
> (In reply to comment #2)
> 
> I see two quick solutions:

I have noticed that your replies have weird quoting. For example in
comment#3 I would have expected to see

> I see two quick solutions:

instead of

I see two quick solutions:

when you do reply, doesn't bugzilla automatically do this for you ?
It could lead to confusion in future for a reader.
Comment 6 Manoj N Palat CLA 2013-03-15 00:54:05 EDT
(In reply to comment #5)
> when you do reply, doesn't bugzilla automatically do this for you ?
Unfortunately, IE doesn't do this for all the lines, while chrome and firefox does.
> It could lead to confusion in future for a reader.
Comment 7 Manoj N Palat CLA 2013-03-15 03:04:56 EDT
Created attachment 228459 [details]
Proposed Patch
Comment 8 Srikanth Sankaran CLA 2013-03-15 03:56:07 EDT
(In reply to comment #0)
> ASTs before JLS8 must not try to create nodes that are only allowed in JLS8.
> 
> Hint: Open a call hierarchy on ASTNode#unsupportedIn2_3_4() and make sure
> all accesses are properly protected. You may want to set "Search Scope >
> Project" in the view menu.

Checking: was this step done ? Are we in the clear ?
Comment 9 Manoj N Palat CLA 2013-03-15 04:27:46 EDT
(In reply to comment #8)
> (In reply to comment #0)
> > ASTs before JLS8 must not try to create nodes that are only allowed in JLS8.
> > 
> > Hint: Open a call hierarchy on ASTNode#unsupportedIn2_3_4() and make sure
> > all accesses are properly protected. You may want to set "Search Scope >
> > Project" in the view menu.
> 
> Checking: was this step done ? Are we in the clear ?

Yes. Have checked all the cases except calls in tests. All the accesses are either  protected with a level check directly or indirectly (in a call above or with a if based on level check) or the method is documented to throw unsupported exception (eg: ASTNode:newLambdaExpression).

[Did n't check the tests since 1)the tests have to go through any of the above entry points and 2) tests would have given an exception if there was a case otherwise]
Comment 10 Srikanth Sankaran CLA 2013-03-15 06:43:06 EDT
Fix and tests released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=253db1ad159947db401a053aab34e948bedb1e92

Thanks Manoj.