]> source.dussan.org Git - aspectj.git/commitdiff
Fix 485583: NullPointerException in org.aspectj.ajdt.internal.compiler.ast.PointcutDe...
authorAndy Clement <aclement@pivotal.io>
Wed, 10 Feb 2016 23:46:53 +0000 (15:46 -0800)
committerAndy Clement <aclement@pivotal.io>
Wed, 10 Feb 2016 23:46:53 +0000 (15:46 -0800)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
tests/bugs189/485583/Bar.aj [new file with mode: 0644]
tests/bugs189/485583/Foo.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc189/Ajc189Tests.java
tests/src/org/aspectj/systemtest/ajc189/ajc189.xml

index 3d9990ad19f4b3847f9fe30725b5579479357296..087e87d6cce0ef1630c59290641d98cc0f38a6d6 100644 (file)
@@ -26,9 +26,11 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclarat
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference;
 import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
+import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TagBits;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
 import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
@@ -89,17 +91,7 @@ public class PointcutDeclaration extends AjMethodDeclaration {
                // }
 
                if (Modifier.isAbstract(this.declaredModifiers)) {
-                       if (!(typeDec instanceof AspectDeclaration)) {
-                               // check for @Aspect
-                               if (isAtAspectJ(typeDec)) {
-                                       // no need to check abstract class as JDT does that
-                               } else {
-                                       typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
-                                                       "The abstract pointcut " + new String(declaredName) + " can only be defined in an aspect");
-                                       ignoreFurtherInvestigation = true;
-                                       return;
-                               }
-                       } else if (!Modifier.isAbstract(typeDec.modifiers)) {
+                       if ((typeDec instanceof AspectDeclaration) && !Modifier.isAbstract(typeDec.modifiers)) {
                                typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
                                                "The abstract pointcut " + new String(declaredName) + " can only be defined in an abstract aspect");
 
@@ -116,10 +108,9 @@ public class PointcutDeclaration extends AjMethodDeclaration {
        private boolean isAtAspectJ(TypeDeclaration typeDec) {
                if (typeDec.annotations == null)
                        return false;
-
                for (int i = 0; i < typeDec.annotations.length; i++) {
                        Annotation annotation = typeDec.annotations[i];
-                       if ("Lorg/aspectj/lang/annotation/Aspect;".equals(new String(annotation.resolvedType.signature()))) {
+                       if (CharOperation.equals(annotation.resolvedType.signature(),ASPECT_CHARS)) {
                                return true;
                        }
                }
@@ -174,6 +165,8 @@ public class PointcutDeclaration extends AjMethodDeclaration {
                generateSyntheticPointcutMethod = true;
                // mangleSelector = false;
        }
+       
+       private static char[] ASPECT_CHARS = "Lorg/aspectj/lang/annotation/Aspect;".toCharArray();
 
        public void resolve(ClassScope upperScope) {
                // we attempted to resolve annotations below, but that was too early, so we do it again
@@ -181,6 +174,18 @@ public class PointcutDeclaration extends AjMethodDeclaration {
                if (binding != null) {
                        binding.tagBits -= TagBits.AnnotationResolved;
                        resolveAnnotations(scope, this.annotations, this.binding);
+                       
+                       TypeDeclaration typeDec = upperScope.referenceContext;
+                       if (Modifier.isAbstract(this.declaredModifiers)) {
+                               if (!(typeDec instanceof AspectDeclaration)) {
+                                       if (!isAtAspectJ(typeDec)) {
+                                               typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
+                                                               "The abstract pointcut " + new String(declaredName) + " can only be defined in an aspect");
+                                               ignoreFurtherInvestigation = true;
+                                               return;                                 
+                                       }
+                               }
+                       }
                }
                // for the rest of the resolution process, this method should do nothing, use the entry point below...
        }
index dc82d4aac54259af1a66e24442da406a6b60bdcd..174f272158034a7c671a299643b1183c324dbe3e 100644 (file)
@@ -465,11 +465,11 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
                        }
                        if (pointcuts[i].isAbstract()) {
                                if (!this.isAspect()) {
-                                       eclipseWorld().showMessage(IMessage.ERROR, "abstract pointcut only allowed in aspect" + pointcuts[i].getName(),
+                                       eclipseWorld().showMessage(IMessage.ERROR, "The abstract pointcut " + pointcuts[i].getName()+ " can only be defined in an aspect",
                                                        pointcuts[i].getSourceLocation(), null);
                                        sawError = true;
                                } else if (!binding.isAbstract()) {
-                                       eclipseWorld().showMessage(IMessage.ERROR, "abstract pointcut in concrete aspect" + pointcuts[i],
+                                       eclipseWorld().showMessage(IMessage.ERROR, "abstract pointcut in concrete aspect" + pointcuts[i],
                                                        pointcuts[i].getSourceLocation(), null);
                                        sawError = true;
                                }
diff --git a/tests/bugs189/485583/Bar.aj b/tests/bugs189/485583/Bar.aj
new file mode 100644 (file)
index 0000000..aa69e37
--- /dev/null
@@ -0,0 +1,8 @@
+//import org.aspectj.lang.annotation.*;
+//
+//@SuppressLoggerWarning
+@org.aspectj.lang.annotation.Aspect
+public abstract class  Bar {    
+    public abstract pointcut applicationCode();
+}
+
diff --git a/tests/bugs189/485583/Foo.aj b/tests/bugs189/485583/Foo.aj
new file mode 100644 (file)
index 0000000..3997385
--- /dev/null
@@ -0,0 +1,4 @@
+
+public abstract class Foo {
+    public abstract pointcut deprecatedCode();
+}
index 138787853b69619c3c8e245a0b3f62b2098cbf2d..a3a191a616913bfe1a0eb551ade4052cba113379 100644 (file)
@@ -22,6 +22,10 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  */
 public class Ajc189Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+       public void testNPEAtAspectJ() throws Exception {
+               runTest("NPE at aspectj");
+       }
+       
        public void testLostBounds() throws Exception {
                runTest("lost bounds");
                // This type has I added via declare parents
index 594f7f11d8794b92c556f6c921f4bcc3b3969dfa..586ff771eaeebcb2c9f012533696a665ba0872fa 100644 (file)
@@ -2,6 +2,12 @@
 
 <suite>
 
+<ajc-test dir="bugs189/485583" title="NPE at aspectj">
+  <compile files="Foo.aj Bar.aj" options="-1.8">
+  <message kind="error" text="The abstract pointcut deprecatedCode can only be defined in an aspect"/>
+  </compile>
+</ajc-test>
+
 <ajc-test dir="bugs189/486612" title="lost bounds">
   <compile files="Code.java Azpect.java" options="-1.8"/>
 </ajc-test>