Community
Participate
Working Groups
I will attach a project that causes the following exception when opened in eclipse 3.2RC4 with jdk 1.5. If you open the model.Project class, you will get this exception in the error log. If you add the java.lang.Collection import, the exception no longer occurs. It's somehow related to the annotation being there and having a compiler error elsewhere in the class. I can also repeat the exception with this as the Project class body (notice the lower case string): { private string asdf; @GeneratedValue(strategy=GenerationType.TABLE, generator = "jkljljk") private int projectId; } java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.binarySearch(ReferenceBinding.java:76) at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getField(SourceTypeBinding.java:845) at org.eclipse.jdt.internal.compiler.lookup.Scope.findField(Scope.java:826) at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding(Scope.java:1412) at org.eclipse.jdt.internal.compiler.lookup.BlockScope.getBinding(BlockScope.java:424) at org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference.resolveType(QualifiedNameReference.java:972) at org.eclipse.jdt.internal.compiler.ast.MemberValuePair.resolveTypeExpecting(MemberValuePair.java:83) at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:266) at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:513) at org.eclipse.jdt.internal.compiler.lookup.FieldBinding.getAnnotationTagBits(FieldBinding.java:252) at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(SourceTypeBinding.java:1226) at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:603) at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:582) at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:427) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:587) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:411) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:300)
Created attachment 42281 [details] Test case project
Reduced testcase: class X { @Ann(m=Object) private int foo; private NonExisting bar; } @interface Ann { String m(); }
Created attachment 42299 [details] Proposed fix Simple fix that reverts to a linear search if one of the field binding is null.
Created attachment 42301 [details] Patch to clean up field array The problem is in the method SourceTypeBinding.fields(). It nulls out a field when it detects that its type cannot be resolved, but continues to resolve the other fields, which cause an Annotation type to be resolved. We end up in getField where the null'ed out field is detected. The proposed patch uses a separate set to keep track of the failed fields and builds the new field array but skipping the failed ones.
We should make a similar change to SourceTypeBinding.methods() so failed methods are not null'ed out immediately.
Problem comes from annotation resolution (looking for @Deprecated) which is reentering field resolution (while fields are being resolved) to resolve 'Object' reference. Here is a scenario with methods, which doesn't cause any NPE: public class X { @Ann(m=Object()) private void foo(){} private NonExisting bar(){} } @interface Ann { String m(); }
Previous case doesn't fail, since unresolved return type is not directly nulling out the entry in method array. Here is another case which causes a NPE with methods: public class X { @Ann(m=bar()) private void foo(){} private NonExisting bar(NonExisting ne){} } @interface Ann { String m(); }
My fix is along the same line as Kent's proposed one, except using an array which makes the logic closer to original one (especially on method scenario). Added AnnotationTest#test202-207
Created attachment 42942 [details] Proposed patch
The scenario is rather rare, it arises through annotation resolution and in presence of unresolved types. This is why it is safer to queue this one for 3.2.1, as opposed to RC7 where we want to be really conservative.
Created attachment 42948 [details] Better patch Had forgotten to use resolvedMethod in methods() when finding collisions
Added AnnotationTest#test202-207. Released fix for 3.2.1
Released for 3.2.1 Released for 3.3 M1 while merging TARGET_321 in HEAD
*** Bug 146858 has been marked as a duplicate of this bug. ***
Verified for 3.3 M1 using build I20060807-2000.
Verified for 3.2.1 using build M20060908-1655