Bug 148797 - Syntax error in java class results in AST=null-error on "organize imports"
Summary: Syntax error in java class results in AST=null-error on "organize imports"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-27 07:10 EDT by Volker Renneberg CLA
Modified: 2006-08-04 11:40 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix for recovery and regenerated parser files (804 bytes, application/x-zip-compressed)
2006-06-30 06:03 EDT, David Audel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Renneberg CLA 2006-06-27 07:10:34 EDT
Hi!

I am using Eclipse 3.2RC7.
The following code 
public class TestIt {
   public void a() {
      Object a = null;
      for (Object o : a.getClass()()) {

      }
   }
}

produces an unexpected error during organize imports: AST must not be null.

Is this a bug or a feature?

I simple create a class with the given code, paste the code, and press the shortcut for "Organize imports".

Best regards
Volker
Comment 1 Olivier Thomann CLA 2006-06-29 10:48:53 EDT
Reproduced.
I am investigating.
Stack trace is:
java.lang.NullPointerException
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1520)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1715)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2366)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:511)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:179)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2659)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1242)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:253)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:856)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:630)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider$1.run(ASTProvider.java:605)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:600)
Comment 2 Olivier Thomann CLA 2006-06-29 10:56:17 EDT
This is a case where the recovery cannot recover the collection of the foreach statement.
I suggest deleting the foreach statement in this case.
David, is this fine for you or you believe you can end up with a non-null expression for the collection (a.getClass()() in this case) ?
Comment 3 Olivier Thomann CLA 2006-06-29 11:01:55 EDT
Philippe,

Do you want it for 3.2.1 ?
Comment 4 Olivier Thomann CLA 2006-06-29 12:13:37 EDT
Fixed the ast converter to handle null collection when the recovery cannot recover the collection expression of foreach statement.
The statement is purely removed from the resulting DOM/AST tree.
Add regression test: org.eclipse.jdt.core.tests.dom.ASTConverter15Test.test0222.
David, once you fix the recovery, update this test to reflect that the foreach statement is still there.
Comment 5 David Audel CLA 2006-06-30 06:03:34 EDT
Created attachment 45573 [details]
Proposed fix for recovery and regenerated parser files
Comment 6 David Audel CLA 2006-06-30 06:36:18 EDT
Released for 3.3 M1.

Test updated: ASTConverter15Test#test0222()
Comment 7 Frederic Fusier CLA 2006-08-04 11:40:56 EDT
Verified for 3.3 M1 using build I20060804-0010.