Community
Participate
Working Groups
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
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)
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) ?
Philippe, Do you want it for 3.2.1 ?
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.
Created attachment 45573 [details] Proposed fix for recovery and regenerated parser files
Released for 3.3 M1. Test updated: ASTConverter15Test#test0222()
Verified for 3.3 M1 using build I20060804-0010.