Bug 121327 - DOMParser.createASTs() NPE at FieldReference.getConstantFor(FieldReference.java:408)
Summary: DOMParser.createASTs() NPE at FieldReference.getConstantFor(FieldReference.ja...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.1.2   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-17 23:12 EST by Stefan Reich CLA
Modified: 2006-01-11 10:50 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Reich CLA 2005-12-17 23:12:16 EST
Please backport this fix for the 3.1.2 release. My plugin runs into this problem very frequently, and another half year will pass for the 3.2 release. My customers and I can't wait that long.

Thanks a lot!
Stefan Reich


+++ This bug was initially created as a clone of Bug #111822 +++

Stack trace:
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ast.FieldReference.getConstantFor
(FieldReference.java:408)
	at 
org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference.getOtherFieldBindi
ngs(QualifiedNameReference.java:657)
	at 
org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference.resolveType
(QualifiedNameReference.java:880)
	at 
org.eclipse.jdt.internal.compiler.ast.MemberValuePair.resolveTypeExpecting
(MemberValuePair.java:70)
	at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType
(Annotation.java:255)
	at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations
(ASTNode.java:466)
	at 
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getAnnotationTagBits
(SourceTypeBinding.java:720)
	at 
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForField
sAndMethods(SourceTypeBinding.java:618)
	at 
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes
(CompilationUnitScope.java:420)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve
(CompilationUnitResolver.java:721)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve
(CompilationUnitResolver.java:460)
	at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:664)
	at fp.MyAnnoProcessor.process(MyAnnoProcessor.java:45)
	at 
org.eclipse.jdt.apt.core.internal.APTDispatchRunnable.runAPTInFileBasedMode
(APTDispatchRunnable.java:309)
	at org.eclipse.jdt.apt.core.internal.APTDispatchRunnable.runAPT
(APTDispatchRunnable.java:536)
	at org.eclipse.jdt.apt.core.internal.APTDispatchRunnable.runAPT
(APTDispatchRunnable.java:442)
	at org.eclipse.jdt.apt.core.internal.APTDispatchRunnable.run
(APTDispatchRunnable.java:192)
	at org.eclipse.jdt.apt.core.internal.APTDispatch.runAPT
(APTDispatch.java:99)
	at org.eclipse.jdt.apt.core.internal.APTDispatch.runAPTDuringReconcile
(APTDispatch.java:58)
	at 
org.eclipse.jdt.apt.core.internal.AptCompilationParticipant.preReconcileNotify
(AptCompilationParticipant.java:180)
	at org.eclipse.jdt.apt.core.internal.AptCompilationParticipant.notify
(AptCompilationParticipant.java:88)
	at 
org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.notifyCompilationPa
rticipants(ReconcileWorkingCopyOperation.java:144)
	at 
org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation
(ReconcileWorkingCopyOperation.java:58)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:718)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation
(JavaModelOperation.java:777)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile
(CompilationUnit.java:1081)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run
(JavaReconcilingStrategy.java:98)
	at org.eclipse.core.internal.runtime.InternalPlatform.run
(InternalPlatform.java:1044)
	at org.eclipse.core.runtime.Platform.run(Platform.java:783)
	at 
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile
(JavaReconcilingStrategy.java:82)
	at 
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile
(JavaReconcilingStrategy.java:147)
	at 
org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile
(CompositeReconcilingStrategy.java:86)
	at 
org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile
(JavaCompositeReconcilingStrategy.java:94)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process
(MonoReconciler.java:75)
	at org.eclipse.jdt.internal.ui.text.JavaReconciler.process
(JavaReconciler.java:339)
	at 
org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run
(AbstractReconciler.java:204)


Repro: 
Create a java project with the following three java files.
package pkg;
RefAnnoAndClassWithAnno.java :
public class RefMyAnnoAndClassWithAnno {
	final Class anno = MyAnno.class;
	final Class withAnno = ClassWithAnnotation.class;	
}

MyAnno.java :
public @interface MyAnno {	
	public enum EnumColor{
		BLUE, RED, WHITE;
	}	
	EnumColor aEnum();
}

ClassWithAnnotation.java:
package pkg;
import pkg.MyAnno.EnumColor;

@MyAnno(aEnum = EnumColor.BLUE)
public class ClassWithAnnotation {}


If you invoke the following code against the project you just created, you 
will get the NPE.

/* Ask for type "pkg.RefMyAnnoAndClassWithAnno" through 
 DOMParser.createASTs() passing in only the binding key and no compilation 
unit*/
void process(){
    class BindingRequestor extends ASTRequestor{}
    String key = BindingKey.createTypeBindingKey
("pkg.RefMyAnnoAndClassWithAnno");
    final ASTParser parser = ASTParser.newParser(AST.JLS3);
    final BindingRequestor requestor = new BindingRequestor();
    parser.setResolveBindings(true);		
    parser.setProject(/*the java project with the three java files*/);
    parser.createASTs(new ICompilationUnit[0], new String[]{key}, requestor, 
null);
}

On my machine, i used APT to dispatch to an annotation processor that runs the 
above process() code that's why the stack trace contains APT in it. APT does 
not do anything that would influence the behavior of the bug. 
(Let me know if you need anything else to repro the problem.)

It does not matter whether the process() code is invoked during reconcile or 
build. 

What I observed:
1) CompilationUnitResolver.resolve(ICompilationUnit[], String[], ASTRequestor 
astRequestor, int, Map, WorkingCopyOwner) calls Compiler.process(..) and 
resolve type "pkg.RefMyAnnoAndClassWithAnno".
2) Compiler.process() puts "pkg.MyAnno" and "pkg.ClassWithAnnotation" on the 
queue (unitsToProcess) to be processed.
3) resolution of "pkg.RefMyAnnoAndClassWithAnno" completes, reports the 
binding. Then cuts the reference to the AST for the type.
4) calls faultInTypes() on "pkg.MyAnno". At completion, cuts the AST.
5) calls faultInTypes() on "pkg.ClassWithAnnotation".
6) Since "pkg.ClassWithAnnotation" has an annotation, then the compiler go 
resolve the annotations. 
7) NPE occurs since the annotation reference an enum constant in "pkg.MyAnno" 
and the constant has never been resolved and the AST for it is already cut.
Comment 1 Olivier Thomann CLA 2005-12-19 13:02:24 EST
Don't set the target milestone. We set the value when the problem is fixed.
What version of APT are you using?

Moving to JDT/APT for investigation.
Comment 2 Theodora Yeung CLA 2005-12-19 19:43:36 EST
Jess, 
The fix is back ported to the jdt.core version that apt is running on. 
Question: What version of apt is published to the update site? 

Comment 3 Jess Garms CLA 2005-12-19 20:18:13 EST
The latest version on the update site (3.1.1_apt02) was released on 10-21-05, so should contain the fix for 111822. Stefan, is that the version you're using? Thanks.
Comment 4 Stefan Reich CLA 2005-12-19 23:23:50 EST
Thank you all for your quick response!

My plugin seems to trigger this problem differently and don't use APT. I am using Eclipse 3.1.1, and I see this error only on code that contains annotations (the Java 6 source code in my case). Here is a typical stack trace:

java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.ast.FieldReference.getConstantFor(FieldReference.java:406)
at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.checkFieldAccess(SingleNameReference.java:164)
at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.resolveType(SingleNameReference.java:703)
at org.eclipse.jdt.internal.compiler.ast.Expression.resolveTypeExpecting(Expression.java:848)
at org.eclipse.jdt.internal.compiler.ast.ArrayInitializer.resolveTypeExpecting(ArrayInitializer.java:177)
at org.eclipse.jdt.internal.compiler.ast.MemberValuePair.resolveTypeExpecting(MemberValuePair.java:61)
at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:246)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:436)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getAnnotationTagBits(SourceTypeBinding.java:701)
at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:328)
at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:436)
at org.eclipse.jdt.internal.compiler.lookup.MethodBinding.getAnnotationTagBits(MethodBinding.java:411)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1198)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1011)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:617)
at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:620)
at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:393)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:713)
at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:455)
at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:664)
at com.jutils.lint4j.eclipse.actions.NewAuditAction.audit(NewAuditAction.java:170)
at com.jutils.lint4j.eclipse.actions.NewAuditAction$1.run(NewAuditAction.java:57)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
Comment 5 Jess Garms CLA 2005-12-20 12:16:25 EST
Ah, I see. You just want the fix that was put in the APT branch also back-ported to the maintenance release of standard (non-APT) Eclipse 3.1.2. Assigning back to jdt-core so they can make that decision.
Comment 6 Philipe Mulet CLA 2006-01-10 07:45:10 EST
+1 for 3.1.2
Comment 7 Jerome Lanneluc CLA 2006-01-10 08:04:04 EST
In fact, fix for bug 111822 was not perfect and introduced a performance problem reported in bug 114935.

So I backported the fix for bug 114935 to the R3_1_maintenance stream instead.
Also backported corresponding tests BatchASTCreationTests#test069() and test070().
Comment 8 Frederic Fusier CLA 2006-01-11 10:50:50 EST
Verified for 3.1.2 using build M20060111-0800.