]> source.dussan.org Git - aspectj.git/commitdiff
Fix for 64331
authoraclement <aclement>
Wed, 28 Jul 2004 14:43:40 +0000 (14:43 +0000)
committeraclement <aclement>
Wed, 28 Jul 2004 14:43:40 +0000 (14:43 +0000)
   java.lang.NullPointerException in WeaverMessageHandler class

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/WeaverMessageHandler.java
tests/ajcTests.xml
tests/bugs/abstractITDs/A.java [new file with mode: 0644]
tests/bugs/abstractITDs/B.aj [new file with mode: 0644]
tests/bugs/abstractITDs/B.jar [new file with mode: 0644]
tests/bugs/abstractITDs/C.java [new file with mode: 0644]
tests/bugs/abstractITDs/buildBJar.bat [new file with mode: 0644]
weaver/src/org/aspectj/weaver/ResolvedTypeX.java

index 71017a6c398ff954c2973403221ee53c17145445..a379fccb6b6447edf7e21ee5e1b9d6429c31508e 100644 (file)
@@ -10,6 +10,7 @@
  *******************************************************************************/
 package org.aspectj.ajdt.internal.compiler;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
@@ -164,12 +165,13 @@ public class WeaverMessageHandler implements IMessageHandler {
        private IProblem[] buildSeeAlsoProblems(List sourceLocations,
                                                                                        CompilationResult problemSource,
                                                                                        boolean usedBinarySourceFileName) {
-               int probLength = sourceLocations.size();
-               if (usedBinarySourceFileName) probLength++;
-               IProblem[] ret = new IProblem[probLength];
+               List ret = new ArrayList();
+
                for (int i = 0; i < sourceLocations.size(); i++) {
                        ISourceLocation loc = (ISourceLocation) sourceLocations.get(i);
-                       ret[i] = new DefaultProblem(loc.getSourceFile().getPath().toCharArray(),
+                       if (loc != null ) {
+                               DefaultProblem dp = 
+                                       new DefaultProblem( loc.getSourceFile().getPath().toCharArray(),
                                                                                "see also",
                                                                                0,
                                                                                new String[] {},
@@ -177,13 +179,19 @@ public class WeaverMessageHandler implements IMessageHandler {
                                                                                getStartPos(loc,null),
                                                                                getEndPos(loc,null),
                                                                                loc.getLine());
+                         ret.add(dp);
+                       } else {
+                               throw new RuntimeException("Internal Compiler Error: Unexpected null source location passed as 'see also' location.");
+                       }
                }
                if (usedBinarySourceFileName) {
-                       ret[ret.length -1] = new DefaultProblem(problemSource.fileName,"see also",0,new String[] {},
+                       DefaultProblem dp = new DefaultProblem(problemSource.fileName,"see also",0,new String[] {},
                                                                                                        ProblemSeverities.Ignore,0,
                                                                                                        0,0);
+                       ret.add(dp);
                }
-               return ret;
+               IProblem[] retValue = (IProblem[])ret.toArray(new IProblem[]{});
+               return retValue;
        }
 }
 
index 85c36164b80785d1fb3a39c8965979d41d4aa236..f76405da30ea2071154f6b4e8a4a2c9df8627566 100644 (file)
         </compile>
     </ajc-test>
     
+    <ajc-test dir="bugs/abstractITDs"
+               pr="64331" title="java.lang.NullPointerException in WeaverMessageHandler class">
+        <compile files="A.java,C.java" aspectpath="B.jar">
+          <message kind="error" line="1" text="must implement abstract inter-type declaration: void A.foo()"/>
+        </compile>
+    </ajc-test>
+    
 </suite>
diff --git a/tests/bugs/abstractITDs/A.java b/tests/bugs/abstractITDs/A.java
new file mode 100644 (file)
index 0000000..5d9e777
--- /dev/null
@@ -0,0 +1,2 @@
+public abstract class A {
+}
diff --git a/tests/bugs/abstractITDs/B.aj b/tests/bugs/abstractITDs/B.aj
new file mode 100644 (file)
index 0000000..54af323
--- /dev/null
@@ -0,0 +1,3 @@
+public aspect B {\r
+       abstract public void A.foo();\r
+}
\ No newline at end of file
diff --git a/tests/bugs/abstractITDs/B.jar b/tests/bugs/abstractITDs/B.jar
new file mode 100644 (file)
index 0000000..b0fcaad
Binary files /dev/null and b/tests/bugs/abstractITDs/B.jar differ
diff --git a/tests/bugs/abstractITDs/C.java b/tests/bugs/abstractITDs/C.java
new file mode 100644 (file)
index 0000000..8e66137
--- /dev/null
@@ -0,0 +1,2 @@
+public class C extends A {
+}
\ No newline at end of file
diff --git a/tests/bugs/abstractITDs/buildBJar.bat b/tests/bugs/abstractITDs/buildBJar.bat
new file mode 100644 (file)
index 0000000..4905f25
--- /dev/null
@@ -0,0 +1 @@
+ajc A.java B.aj -outjar B.jar\r
index 16634af0761e7519832310027bed5d8c1b6a250e..2779f7cdd8a5fd4f9f25981afa6f21e2736263c0 100644 (file)
@@ -986,10 +986,17 @@ public abstract class ResolvedTypeX extends TypeX {
         for (Iterator iter = getInterTypeMungersIncludingSupers().iterator(); iter.hasNext();) {
                        ConcreteTypeMunger element = (ConcreteTypeMunger) iter.next();
             if (element.getSignature() != null && element.getSignature().isAbstract()) {
+               ISourceLocation xtraLocation = element.getSourceLocation();
+               if (xtraLocation == null) {
+                       // Until intertype mungers remember where they came from, the source location
+                       // for the element is null when binary weaving.  In these cases uses the
+                       // source location for the aspect containing the ITD
+                               xtraLocation = element.getAspectType().getSourceLocation();
+               }
                 world.getMessageHandler().handleMessage(
                     new Message("must implement abstract inter-type declaration: " + element.getSignature(),
                         "", IMessage.ERROR, getSourceLocation(), null, 
-                        new ISourceLocation[] { element.getSourceLocation() }));
+                        new ISourceLocation[] { xtraLocation }));
             }
                }
     }