]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bugzilla Bug 51320
authoraclement <aclement>
Wed, 25 Feb 2004 11:14:32 +0000 (11:14 +0000)
committeraclement <aclement>
Wed, 25 Feb 2004 11:14:32 +0000 (11:14 +0000)
   ClasscastException on concretization of if(false)
(i.e. you can't use if/target/args/cflow/cflowbelow/this in deow - you get an error if you try)

tests/ajcTests.xml
tests/bugs/DecwClassCastException.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java
weaver/src/org/aspectj/weaver/patterns/IfPointcut.java
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java

index 6b7f1505062eb1e3f35e03c1ca98b4b38b08f128..5f2210e347026909cd9e228723be1162cd877891 100644 (file)
         title="Polymorphic ITD fails in CVS HEAD (From ajdt 1.1.6)">
         <compile files="OverloadedITDNPE.java" />
     </ajc-test>
+    
+    <ajc-test dir="bugs" pr="51320"
+        title="ClasscastException on concretization of if(false)">
+        <compile files="DecwClassCastException.java">
+        
+         <!-- These are the illegal PCDs against a deow -->
+         <message kind="error" line="27" text="if() pointcut designator cannot be used"/>
+         <message kind="error" line="29" text="if() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="31" text="cflow() pointcut designator cannot be used"/>
+         <message kind="error" line="33" text="cflow() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="35" text="cflowbelow() pointcut designator cannot be used"/>
+         <message kind="error" line="37" text="cflowbelow() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="39" text="this() pointcut designator cannot be used"/>
+         <message kind="error" line="41" text="this() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="43" text="target() pointcut designator cannot be used"/>
+         <message kind="error" line="45" text="target() pointcut designator cannot be used"/>
+         
+         <message kind="error" line="47" text="args() pointcut designator cannot be used"/>
+         <message kind="error" line="49" text="args() pointcut designator cannot be used"/>
+         
+        </compile>
+    </ajc-test>
        
 </suite>
diff --git a/tests/bugs/DecwClassCastException.java b/tests/bugs/DecwClassCastException.java
new file mode 100644 (file)
index 0000000..e040a1e
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * From:
+ * 
+ * http://dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/semantics-declare.html#d0e6499
+ *
+ * Pointcuts that appear inside of declare forms have certain restrictions. 
+ * Like other pointcuts, these pick out join points, but they do so in a 
+ * way that is statically determinable. 
+ * 
+ * Consequently, such pointcuts may not include, directly or indirectly 
+ * (through user-defined pointcut declarations) pointcuts that discriminate 
+ * based on dynamic (runtime) context. Therefore, such pointcuts may not be 
+ * defined in terms of
+ * 
+ * cflow
+ * cflowbelow
+ * this
+ * target
+ * args
+ * if
+ * 
+ * all of which can discriminate on runtime information. 
+ */
+
+public aspect DecwClassCastException {
+
+       declare warning : if(true) : "if(true) directly against checker";
+       pointcut p(): if(false);
+       declare warning : p() : "if(false) through defined pointcut";
+       
+       declare error : cflow(execution(* main(..))): "cflow(execution(* main(..))) directly against checker";
+       pointcut p2(): cflow(execution(* main(..)));
+       declare error : p2() : "cflow(execution(* main(..))) through defined pointcut";
+       
+       declare warning : cflowbelow(execution(* main(..))): "cflowbelow(execution(* main(..))) directly against checker";
+       pointcut p3(): cflowbelow(execution(* main(..)));
+       declare error : p3() : "cflowbelow(execution(* main(..))) through defined pointcut";
+       
+       declare warning : this(Object): "this(Object) directly against checker";
+       pointcut p4(): this(Object);
+       declare warning : p4(): "this(Object) through defined pointcut";
+       
+       declare warning : target(Object): "target(Object) directly against checker";
+       pointcut p5(): target(Object);
+       declare warning : p5(): "target(Object) through defined pointcut";
+               
+       declare warning : args(Object): "args(Object) directly against checker";
+       pointcut p6(): args(Object);
+       declare warning : p6(): "args(Object) through defined pointcut";
+       
+
+    public static void main(String[] args) {
+           System.err.println("In main!");
+    }
+    
+}
\ No newline at end of file
index 382ace4add7077eca368774f9dc4830001eddb05..7c64106235b84c34f2ef9b7197843d5b072c32da 100644 (file)
@@ -20,6 +20,7 @@ import java.io.IOException;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.BetaException;
+import org.aspectj.weaver.Checker;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
 import org.aspectj.weaver.ResolvedTypeX;
@@ -88,6 +89,13 @@ public class ArgsPointcut extends NameBindingPointcut {
 
 
        public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
+               if (bindings.getEnclosingAdvice() instanceof Checker) {
+                 // Enforce rule about which designators are supported in deow
+                 inAspect.getWorld().showMessage(IMessage.ERROR,
+                       "args() pointcut designator cannot be used in declare statement",
+                       bindings.getEnclosingAdvice().getSourceLocation(), null);
+                 return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
+               }
                TypePatternList args = arguments.resolveReferences(bindings);
                if (inAspect.crosscuttingMembers != null) {
                        inAspect.crosscuttingMembers.exposeTypes(args.getExactTypes());
index 4c00603e945575645fb29ff0abba31eb85fb94c1..e7d5ac8b9c0261be7249602da96e1efeb61fd025 100644 (file)
@@ -21,9 +21,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.aspectj.bridge.IMessage;
 import org.aspectj.util.FileUtil;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.Advice;
+import org.aspectj.weaver.Checker;
 import org.aspectj.weaver.CrosscuttingMembers;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
@@ -121,6 +123,13 @@ public class CflowPointcut extends Pointcut {
        
        
        public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
+               if (bindings.getEnclosingAdvice() instanceof Checker) {
+                       // Enforce rule about which designators are supported in deow
+                       inAspect.getWorld().showMessage(IMessage.ERROR,
+                         "cflow"+(isBelow?"below":"")+"() pointcut designator cannot be used in declare statement",
+                         bindings.getEnclosingAdvice().getSourceLocation(), null);
+                       return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
+               }
                //make this remap from formal positions to arrayIndices
                IntMap entryBindings = new IntMap();
                for (int i=0, len=freeVars.length; i < len; i++) {
index df4fdb6b5a2512ba488d2b900a4b4a42c831bb5f..6cb181329c084b530e3d70a6ec4fe25194d556a9 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.Advice;
+import org.aspectj.weaver.Checker;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
 import org.aspectj.weaver.ResolvedMember;
@@ -146,6 +147,16 @@ public class IfPointcut extends Pointcut {
        private IfPointcut partiallyConcretized = null;
        public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
                //System.err.println("concretize: " + this + " already: " + partiallyConcretized);
+               
+               if (bindings.getEnclosingAdvice() instanceof Checker) {
+                       // Enforce rule about which designators are supported in deow
+                       inAspect.getWorld().showMessage(IMessage.ERROR,
+                         "if() pointcut designator cannot be used in declare statement",
+                         bindings.getEnclosingAdvice().getSourceLocation(),
+                         null);
+                       return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
+               }
+               
                if (partiallyConcretized != null) {
                        return partiallyConcretized;
                }
@@ -153,7 +164,11 @@ public class IfPointcut extends Pointcut {
                partiallyConcretized = ret;
                if (bindings.directlyInAdvice()) {
                        ShadowMunger advice = bindings.getEnclosingAdvice();
-                       ret.baseArgsCount = ((Advice)advice).getBaseParameterCount();
+                       if (advice instanceof Advice) {
+                               ret.baseArgsCount = ((Advice)advice).getBaseParameterCount();
+                       } else {
+                               ret.baseArgsCount = 0;
+                       }
                        ret.residueSource = advice.getPointcut().concretize(inAspect, ret.baseArgsCount, advice);
                } else {
                        ResolvedPointcutDefinition def = bindings.peekEnclosingDefinitition();
index f17a5a15c57ef6ac43f7c70852746d70428de26b..814370f15043b9ca12f17d33a0db34b9fae4482e 100644 (file)
@@ -17,7 +17,9 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 
+import org.aspectj.bridge.IMessage;
 import org.aspectj.util.FuzzyBoolean;
+import org.aspectj.weaver.Checker;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
 import org.aspectj.weaver.ResolvedTypeX;
@@ -115,6 +117,14 @@ public class ThisOrTargetPointcut extends NameBindingPointcut {
        }
 
        public Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
+               if (bindings.getEnclosingAdvice() instanceof Checker) {
+                 // Enforce rule about which designators are supported in deow
+                 inAspect.getWorld().showMessage(IMessage.ERROR,
+                   (isThis?"this":"target")+"() pointcut designator cannot be used in declare statement",
+                   bindings.getEnclosingAdvice().getSourceLocation(), null);
+                 return Pointcut.makeMatchesNothing(Pointcut.CONCRETE);
+               }
+               
                TypePattern newType = type.remapAdviceFormals(bindings);
                if (inAspect.crosscuttingMembers != null) {
                        inAspect.crosscuttingMembers.exposeType(newType.getExactType());