]> source.dussan.org Git - aspectj.git/commitdiff
Tests for Bugzilla Bug 62458
authoraclement <aclement>
Tue, 18 May 2004 15:54:05 +0000 (15:54 +0000)
committeraclement <aclement>
Tue, 18 May 2004 15:54:05 +0000 (15:54 +0000)
   An if() pointcut inside a perthis() clause causes an ABORT - null pointer exception in ajc

tests/ajcTests.xml
tests/bugs/IfPerThis/Testcase1.java [new file with mode: 0644]
tests/bugs/IfPerThis/Testcase2.java [new file with mode: 0644]
tests/bugs/IfPerThis/Testcase3.java [new file with mode: 0644]

index d30ddb380dfc6d3f753cb65312c434d2fff01ad8..e540a046e3461e603f9eca9c74c3c904cccb6fc2 100644 (file)
                <message kind="error" line="25" file="DisjunctVarBinding_2.java" text="Ambiguous binding of type A"/>
         </compile>
     </ajc-test>
+    
+       <ajc-test dir="bugs/IfPerThis"
+               pr="62458" title="An if() pointcut inside a perthis() clauses an ABORT - null pointer exception in ajc">
+        <compile files="Testcase1.java">
+               <message kind="error" line="15" text="if() pointcut designator cannot be used directly in a per clause"/>
+               <message kind="error" line="23" text="if() pointcut designator cannot be used directly in a per clause"/>
+               <message kind="error" line="25" text="if() pointcut designator cannot be used directly in a per clause"/>
+               <message kind="error" line="27" text="if() pointcut designator cannot be used directly in a per clause"/>
+        </compile>
+    </ajc-test>
+    
+       <ajc-test dir="bugs/IfPerThis"
+               pr="62458" title="An if() pointcut inside a perthis() clauses an ABORT - null pointer exception in ajc">
+        <compile files="Testcase2.java"/>
+        <run class="Testcase2"/>
+    </ajc-test>
+       
+       <ajc-test dir="bugs/IfPerThis"
+               pr="62458" title="An if() pointcut inside a perthis() clauses an ABORT - null pointer exception in ajc">
+        <compile files="Testcase3.java">
+               <message kind="error" line="2" text="if() pointcut designator cannot be used directly in a per clause"/>
+        </compile>
+    </ajc-test>
  
 </suite>
diff --git a/tests/bugs/IfPerThis/Testcase1.java b/tests/bugs/IfPerThis/Testcase1.java
new file mode 100644 (file)
index 0000000..38ea7b1
--- /dev/null
@@ -0,0 +1,27 @@
+public class Testcase1 {
+
+  public static void main(String [] args) {
+       new Testcase1().sayhi();
+  }
+
+  public void sayhi() {
+       System.out.println("Hello World");
+  }
+
+}
+
+// Note the use of an if inside a perthis, causes the ajc compiler to
+//       throw an exception
+aspect Aspect perthis(if(4==3)) {
+               
+       before () : call(* println(..)) && !within(Aspect*) { 
+               System.out.println("Advice 1");
+    }
+
+}
+
+aspect Aspect2 pertarget(if(3==4)) {}
+
+aspect Aspect3 percflow(if(3==4)) {}
+
+aspect Aspect4 percflowbelow(if(3==4)) {}
\ No newline at end of file
diff --git a/tests/bugs/IfPerThis/Testcase2.java b/tests/bugs/IfPerThis/Testcase2.java
new file mode 100644 (file)
index 0000000..42e9dfb
--- /dev/null
@@ -0,0 +1,41 @@
+ aspect Testcase2 perthis(pc1()) {
+
+  pointcut pc1(): execution(* doCommand(..)) && if(commandInterceptionEnabled);
+  private static boolean commandInterceptionEnabled = true;
+
+  public Testcase2() {
+       System.out.println("Created a PerThis aspect : " + this.toString());
+  }
+
+  before(ICommand command) : execution(* doCommand(..)) && this(command) {
+       System.out.println("Invoking command bean:  "+ command);
+  }
+  
+  before(): if(4==3) {
+       
+  }
+
+  public static void main(String[] args) {
+       ICommand c1 = new Command("hello");
+       ICommand c2 = new Command("hello again");
+       c1.doCommand();
+       c2.doCommand();
+  }
+
+}
+
+interface ICommand {
+   void doCommand();
+}
+
+class Command implements ICommand {
+  private String output = "";
+
+  public Command(String s) { this.output = s; }
+
+  public void doCommand() {
+       System.out.println(output + "(" + this + ")");
+  }
+   
+}
\ No newline at end of file
diff --git a/tests/bugs/IfPerThis/Testcase3.java b/tests/bugs/IfPerThis/Testcase3.java
new file mode 100644 (file)
index 0000000..c298343
--- /dev/null
@@ -0,0 +1,37 @@
+// Compiler limitation, can't put if() directly in per clause 
+aspect Testcase3 perthis(execution(* doCommand(..)) && if(commandInterceptionEnabled)) {
+
+  private static boolean commandInterceptionEnabled = true;
+
+  public Testcase3() {
+       System.out.println("Created a PerThis aspect : " + this.toString());
+  }
+
+  before(ICommand command) : execution(* doCommand(..)) && this(command) {
+       System.out.println("Invoking command bean:  "+ command);
+  }
+
+  public static void main(String[] args) {
+       ICommand c1 = new Command("hello");
+       ICommand c2 = new Command("hello again");
+       c1.doCommand();
+       c2.doCommand();
+  }
+
+}
+
+interface ICommand {
+   void doCommand();
+}
+
+class Command implements ICommand {
+  private String output = "";
+
+  public Command(String s) { this.output = s; }
+
+  public void doCommand() {
+       System.out.println(output + "(" + this + ")");
+  }
+   
+}
\ No newline at end of file