Community
Participate
Working Groups
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.
correction to the repro: All three java files are in the same package "pkg".
Thanks for the test case Theodora. Indeed the problem happens because the constant has not been initialized when MyAnno.java since it was not injected in the loop. Changed CompilationUnitResolver#resolve(ICompilationUnit[], ...) to force a resolve() after the faultInTypes(). I confirm that I don't see any performance degration (for example, the refactoring performance tests are not impacted). Added regression test BatchASTCreationTests#test069().
Thanks Jerome for the quick turn around. I noticed that the fix is slate for 3.2 M3, is it possible to have the fix also checked into the APT jdt.core branch? thanks.
(In reply to comment #3) > Thanks Jerome for the quick turn around. > I noticed that the fix is slate for 3.2 M3, is it possible to have the fix > also checked into the APT jdt.core branch? thanks. No problem. I just checked in the fix and regression test in the APT branch.
Fix verified in APT land.