From 94d0a4e9eabd5b1d807ae95418cda47a9d8f4371 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 7 Apr 2010 19:24:04 +0000 Subject: [PATCH] 308386 --- .../lookup/EclipseResolvedMember.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java index 21df3705e..82d243f03 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseResolvedMember.java @@ -30,6 +30,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifie import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding; +import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding; import org.aspectj.weaver.AnnotationAJ; import org.aspectj.weaver.BCException; import org.aspectj.weaver.MemberKind; @@ -159,7 +160,17 @@ public class EclipseResolvedMember extends ResolvedMemberImpl { cachedAnnotationTypes = new ResolvedType[annos.length]; for (int i = 0; i < annos.length; i++) { Annotation type = annos[i]; - cachedAnnotationTypes[i] = w.resolve(UnresolvedType.forSignature(new String(type.resolvedType.signature()))); + TypeBinding typebinding = type.resolvedType; + // If there was a problem resolving the annotation (the import couldn't be found) then that can manifest + // here as typebinding == null. Normally errors are reported prior to weaving (so weaving is avoided and + // the null is not encountered) but the use of hasfield/hasmethod can cause early attempts to look at + // annotations and if we NPE here then the real error will not get reported. + if (typebinding == null) { + // Give up now - expect proper error to be reported + cachedAnnotationTypes = ResolvedType.EMPTY_RESOLVED_TYPE_ARRAY; + return cachedAnnotationTypes; + } + cachedAnnotationTypes[i] = w.resolve(UnresolvedType.forSignature(new String(typebinding.signature()))); } } } @@ -210,18 +221,18 @@ public class EclipseResolvedMember extends ResolvedMemberImpl { // Grab the set of bindings with matching selector MethodBinding[] mb = ((MethodBinding) realBinding).declaringClass.getMethods(methodBinding.selector); - if (mb!=null) { - for (int m = 0, max = mb.length; m < max; m++) { - MethodBinding candidate = mb[m]; - if (candidate instanceof InterTypeMethodBinding) { - if (InterTypeMemberFinder.matches(mb[m], methodBinding)) { - InterTypeMethodBinding intertypeMethodBinding = (InterTypeMethodBinding) candidate; - Annotation[] annos = intertypeMethodBinding.sourceMethod.annotations; - return annos; + if (mb != null) { + for (int m = 0, max = mb.length; m < max; m++) { + MethodBinding candidate = mb[m]; + if (candidate instanceof InterTypeMethodBinding) { + if (InterTypeMemberFinder.matches(mb[m], methodBinding)) { + InterTypeMethodBinding intertypeMethodBinding = (InterTypeMethodBinding) candidate; + Annotation[] annos = intertypeMethodBinding.sourceMethod.annotations; + return annos; + } } } } - } return null; // give up! kind of assuming here that the code has other problems (and they will be reported) } return methodDecl.annotations; -- 2.39.5