Community
Participate
Working Groups
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.
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.
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?
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.
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)
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.
+1 for 3.1.2
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().
Verified for 3.1.2 using build M20060111-0800.