Bug 245563

Summary: npe in reconciler
Product: [Eclipse Project] JDT Reporter: Brian Miller <Brian.Miller>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jerome_lanneluc, markus.kell.r, Olivier_Thomann
Version: 3.4   
Target Milestone: 3.5 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix + regression test none

Description Brian Miller CLA 2008-08-28 13:35:32 EDT
Build ID: I20080617-2000  (3.4.0)

Steps To Reproduce:
As soon as this source class is opened, crashes appear in the error log.

----------------------- Bug.java ---------------
class Bug {
	{
		for(Object obj:new Object[]{new Object(){
			int field=method(});
		}});
	}
	int method(int...args){return args.length;}
}

More information:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.traverse(ForeachStatement.java:528)
	at org.eclipse.jdt.internal.compiler.ast.Block.traverse(Block.java:127)
	at org.eclipse.jdt.internal.compiler.ast.Initializer.traverse(Initializer.java:128)
	at org.eclipse.jdt.internal.compiler.parser.Parser.recoverStatements(Parser.java:10124)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:9322)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:9533)
	at org.eclipse.jdt.internal.compiler.ast.Initializer.parseStatements(Initializer.java:82)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.parseMethods(TypeDeclaration.java:813)
	at org.eclipse.jdt.internal.compiler.parser.Parser.getMethodBodies(Parser.java:8513)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:849)
	at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:904)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:182)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:243)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:190)
Comment 1 Olivier Thomann CLA 2008-08-28 14:56:08 EDT
I think in case of recovered statement we simply need to check for null.
Adding a null check makes the statement recovery to complete and the result in the ASTView is pretty good.
Comment 2 Olivier Thomann CLA 2008-08-28 14:57:37 EDT
Created attachment 111238 [details]
Proposed fix + regression test
Comment 3 Olivier Thomann CLA 2008-08-28 14:58:01 EDT
Released for 3.5M2.
Added regression test in org.eclipse.jdt.core.tests.dom.ASTConverter15Test#test0323
Comment 4 Jerome Lanneluc CLA 2008-09-15 12:20:59 EDT
Verified for 3.5M2 using I20080914-2000