@@ -0,0 +1,5 @@ | |||
package test; | |||
public abstract class AbstractExecutable implements AnotherExecutable { | |||
} |
@@ -0,0 +1,5 @@ | |||
package test; | |||
public interface AnotherExecutable extends Executable { | |||
} |
@@ -0,0 +1,6 @@ | |||
package test; | |||
public interface Executable { | |||
void execute(); | |||
} |
@@ -0,0 +1,12 @@ | |||
package test; | |||
public aspect ExecutionAspect { | |||
declare parents: AbstractExecutable implements java.io.Serializable; | |||
pointcut executions(Executable executable): execution(public void Executable.execute()) && this(executable); | |||
void around(Executable executable): executions(executable) { | |||
System.err.println(thisJoinPoint); | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package test; | |||
public aspect RunnableAspect { | |||
// public void Executable.run() { | |||
// execute(); | |||
// } | |||
// | |||
// //declare parents: (Executable+ && !Executable) implements Runnable; | |||
// declare parents: AbstractExecutable implements java.io.Serializable; | |||
} |
@@ -0,0 +1,13 @@ | |||
package test; | |||
public class SecondTestExecutable extends AbstractExecutable { | |||
public void execute() { | |||
// should not happen because of ExecutionAspect prevents execution | |||
throw new RuntimeException(); | |||
} | |||
public static void main(String[] args) { | |||
new SecondTestExecutable().execute(); | |||
} | |||
} |
@@ -0,0 +1,9 @@ | |||
package test; | |||
public class SubTestExecutable extends TestExecutable { | |||
@Override | |||
public void execute() { | |||
super.execute(); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
package test; | |||
public class TestExecutable implements Executable { | |||
public void execute() { | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
package test; | |||
public abstract class AbstractProcessor implements Processor { | |||
} |
@@ -0,0 +1,9 @@ | |||
package test; | |||
import java.util.List; | |||
public interface ListFactory { | |||
<T> List<T> createList(); | |||
<T> List<T> createList(int initialCapacity); | |||
} |
@@ -0,0 +1,30 @@ | |||
package test; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
public aspect ListFactoryAspect { | |||
private ListFactory listFactory = new ListFactory() { | |||
public <T> List<T> createList() { | |||
return new ArrayList<T>(); | |||
}; | |||
public <T> List<T> createList(int initialCapacity) { | |||
return new ArrayList<T>(); | |||
}; | |||
}; | |||
declare parents: Processor implements ListFactoryConsumer; | |||
public ListFactory ListFactoryConsumer.getListFactory() { | |||
return ListFactoryAspect.aspectOf().listFactory; | |||
} | |||
public <T> List<T> ListFactoryConsumer.createList() { | |||
return getListFactory().<T>createList(); | |||
} | |||
public <T> List<T> ListFactoryConsumer.createList(int initialCapacity) { | |||
return getListFactory().<T>createList(initialCapacity); | |||
} | |||
} |
@@ -0,0 +1,6 @@ | |||
package test; | |||
public interface ListFactoryConsumer { | |||
ListFactory getListFactory(); | |||
} |
@@ -0,0 +1,5 @@ | |||
package test; | |||
public interface Processor { | |||
} |
@@ -0,0 +1,16 @@ | |||
package test; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
public class SimpleListFactoryConsumer extends AbstractProcessor { | |||
public void run() { | |||
//List<List<String>> list1 = getListFactory().createList(); | |||
List<List<String>> list2 = this.createList(); | |||
} | |||
public static void main(String[] args) { | |||
new SimpleListFactoryConsumer().run(); | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
abstract aspect Replicate<T> { | |||
protected pointcut broadcast(T servant); | |||
void around(T servant): broadcast(servant) { | |||
System.err.println("around advice executing: servant class is "+servant.getClass()); | |||
proceed(servant); | |||
} | |||
} | |||
aspect ReplicateConcreteB extends Replicate<Boo> { | |||
protected pointcut broadcast(Boo servant) : call(* *.setScene(..)) && target(servant); | |||
} | |||
aspect ReplicateConcreteG extends Replicate<Goo> { | |||
protected pointcut broadcast(Goo servant) : call(* *.setScene(..)) && target(servant); | |||
} | |||
public class Foo { | |||
public static void main(String []argv) { | |||
new Boo().setScene(); | |||
new Goo().setScene(); | |||
} | |||
} | |||
class Boo { | |||
public void setScene() {} | |||
} | |||
class Goo { | |||
public void setScene() {} | |||
} |
@@ -0,0 +1,12 @@ | |||
public class A { | |||
public static void main(String []argv) { | |||
int i = 5; | |||
try { | |||
String s = "3"; | |||
System.out.println(s); | |||
} catch (Exception e) { | |||
System.out.println(i); | |||
} | |||
} | |||
} |
@@ -12,6 +12,14 @@ package org.aspectj.systemtest.ajc160; | |||
import java.io.File; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.JavaClass; | |||
import org.aspectj.apache.bcel.classfile.LineNumberTable; | |||
import org.aspectj.apache.bcel.classfile.Method; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.generic.MethodGen; | |||
import org.aspectj.apache.bcel.util.ClassPath; | |||
import org.aspectj.apache.bcel.util.SyntheticRepository; | |||
import org.aspectj.testing.XMLBasedAjcTestCase; | |||
import junit.framework.Test; | |||
@@ -21,6 +29,102 @@ import junit.framework.Test; | |||
*/ | |||
public class Ajc160Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
/** Complex test that attempts to damage a class like a badly behaved bytecode transformer would and checks if AspectJ can cope. */ | |||
public void testCopingWithGarbage_pr175806_1() throws ClassNotFoundException { | |||
// Compile the program we are going to mess with | |||
runTest("coping with bad tables"); | |||
// Load up the class and the method 'main' we are interested in | |||
JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"A"); | |||
Method[] meths = jc.getMethods(); | |||
Method oneWeWant = null; | |||
for (int i = 0; i < meths.length && oneWeWant==null; i++) { | |||
Method method = meths[i]; | |||
if (method.getName().equals("main")) oneWeWant = meths[i]; | |||
} | |||
/** | |||
* For the main method: | |||
Stack=2, Locals=3, Args_size=1 | |||
0: iconst_5 | |||
1: istore_1 | |||
2: ldc #18; //String 3 | |||
4: astore_2 | |||
5: getstatic #24; //Field java/lang/System.out:Ljava/io/PrintStream; | |||
8: aload_2 | |||
9: invokevirtual #30; //Method java/io/PrintStream.println:(Ljava/lang/String;)V | |||
12: goto 23 | |||
15: pop | |||
16: getstatic #24; //Field java/lang/System.out:Ljava/io/PrintStream; | |||
19: iload_1 | |||
20: invokevirtual #33; //Method java/io/PrintStream.println:(I)V | |||
23: return | |||
Exception table: | |||
from to target type | |||
2 15 15 Class java/lang/Exception | |||
LineNumberTable: | |||
line 4: 0 | |||
line 6: 2 | |||
line 7: 5 | |||
line 8: 15 | |||
line 9: 16 | |||
line 11: 23 | |||
LocalVariableTable: | |||
Start Length Slot Name Signature | |||
0 24 0 argv [Ljava/lang/String; | |||
2 22 1 i I | |||
5 10 2 s Ljava/lang/String; | |||
*/ | |||
ConstantPool cp = oneWeWant.getConstantPool(); | |||
ConstantPoolGen cpg = new ConstantPoolGen(cp); | |||
// Damage the line number table, entry 2 (Line7:5) so it points to an invalid (not on an instruction boundary) position of 6 | |||
oneWeWant.getLineNumberTable().getLineNumberTable()[2].setStartPC(6); | |||
// Should be 'rounded down' when transforming it into a MethodGen, new position will be '5' | |||
// System.out.println("BEFORE\n"+oneWeWant.getLineNumberTable().toString()); | |||
MethodGen toTransform = new MethodGen(oneWeWant,"A",cpg,false); | |||
LineNumberTable lnt = toTransform.getMethod().getLineNumberTable(); | |||
assertTrue("Should have been 'rounded down' to position 5 but is "+lnt.getLineNumberTable()[2].getStartPC(), lnt.getLineNumberTable()[2].getStartPC()==5); | |||
// System.out.println("AFTER\n"+lnt.toString()); | |||
} | |||
public void testCopingWithGarbage_pr175806_2() throws ClassNotFoundException { | |||
// Compile the program we are going to mess with | |||
runTest("coping with bad tables"); | |||
// Load up the class and the method 'main' we are interested in | |||
JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"A"); | |||
Method[] meths = jc.getMethods(); | |||
Method oneWeWant = null; | |||
for (int i = 0; i < meths.length && oneWeWant==null; i++) { | |||
Method method = meths[i]; | |||
if (method.getName().equals("main")) oneWeWant = meths[i]; | |||
} | |||
// see previous test for dump of main method | |||
ConstantPool cp = oneWeWant.getConstantPool(); | |||
ConstantPoolGen cpg = new ConstantPoolGen(cp); | |||
// Damage the local variable table, entry 2 (" 2 22 1 i I") so it points to an invalid start pc of 3 | |||
oneWeWant.getLocalVariableTable().getLocalVariable(1).setStartPC(3); | |||
// Should be 'rounded down' when transforming it into a MethodGen, new position will be '2' | |||
// This next line will go BANG with an NPE if we don't correctly round the start pc down to 2 | |||
MethodGen toTransform = new MethodGen(oneWeWant,"A",cpg,true); | |||
} | |||
public void testGenericAspectGenericPointcut_pr174449() { runTest("problem with generic aspect and generic pointcut");} | |||
public void testGenericAspectGenericPointcut_noinline_pr174449() { runTest("problem with generic aspect and generic pointcut - noinline");} | |||
public void testGenericMethodsAndOrdering_ok_pr171953_2() { runTest("problem with generic methods and ordering - ok");} | |||
public void testGenericMethodsAndOrdering_bad_pr171953_2() { runTest("problem with generic methods and ordering - bad");} | |||
public void testItdAndJoinpointSignatureCollection_ok_pr171953() { runTest("problem with itd and join point signature collection - ok");} | |||
public void testItdAndJoinpointSignatureCollection_bad_pr171953() { runTest("problem with itd and join point signature collection - bad");} | |||
public void testGenericMethodsAndItds_pr171952() { runTest("generic methods and ITDs");} | |||
//public void testUsingDecpAnnotationWithoutAspectAnnotation_pr169428() { runTest("using decp annotation without aspect annotation");} | |||
public void testItdsParameterizedParameters_pr170467() { runTest("itds and parameterized parameters");} | |||
@@ -31,7 +135,7 @@ public class Ajc160Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
public void testIncorrectOptimizationOfIstore_pr166084() { runTest("incorrect optimization of istore"); } | |||
public void testDualParameterizationsNotAllowed_pr165631() { runTest("dual parameterizations not allowed"); } | |||
public void testSuppressWarnings1_pr166238() { | |||
public void testSuppressWarnings1_pr166238() { | |||
runTest("Suppress warnings1"); | |||
} | |||
@@ -47,6 +151,16 @@ public class Ajc160Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc160/ajc160.xml"); | |||
} | |||
public SyntheticRepository createRepos(File cpentry) { | |||
ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path")); | |||
return SyntheticRepository.getInstance(cp); | |||
} | |||
protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException { | |||
SyntheticRepository repos = createRepos(where); | |||
return repos.loadClass(clazzname); | |||
} | |||
} |
@@ -5,6 +5,60 @@ | |||
<!-- first section - dont need a 1.6 vm but fixed in the 1.6 branch of AspectJ --> | |||
<ajc-test dir="bugs160/pr175806" title="coping with bad tables"> | |||
<compile options="-1.5" files="A.java"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr174449" title="problem with generic aspect and generic pointcut"> | |||
<compile options="-1.5" files="Foo.java"/> | |||
<run class="Foo"> | |||
<stderr> | |||
<line text="around advice executing: servant class is class Boo"/> | |||
<line text="around advice executing: servant class is class Goo"/> | |||
</stderr> | |||
</run> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr174449" title="problem with generic aspect and generic pointcut - noinline"> | |||
<compile options="-1.5 -XnoInline" files="Foo.java"/> | |||
<run class="Foo"> | |||
<stderr> | |||
<line text="around advice executing: servant class is class Boo"/> | |||
<line text="around advice executing: servant class is class Goo"/> | |||
</stderr> | |||
</run> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr171953_2" title="problem with generic methods and ordering - ok"> | |||
<compile options="-1.5" files="test/ListFactoryAspect.aj, test/AbstractProcessor.java,test/ListFactory.java,test/ListFactoryConsumer.java,test/Processor.java,test/SimpleListFactoryConsumer.java"> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr171953_2" title="problem with generic methods and ordering - bad"> | |||
<compile options="-1.5" files="test/ListFactory.java,test/ListFactoryConsumer.java,test/SimpleListFactoryConsumer.java,test/Processor.java,test/ListFactoryAspect.aj,test/AbstractProcessor.java"> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr171953" title="problem with itd and join point signature collection - bad"> | |||
<compile options="-1.5 -showWeaveInfo" files="test/AbstractExecutable.java,test/AnotherExecutable.java,test/Executable.java,test/ExecutionAspect.aj,test/SecondTestExecutable.java test/SubTestExecutable.java test/TestExecutable.java"> | |||
<message kind="weave" text="Join point 'method-execution(void test.SecondTestExecutable.execute())' in Type 'test.SecondTestExecutable' (SecondTestExecutable.java:5) advised by around advice from 'test.ExecutionAspect' (ExecutionAspect.aj:9)"/> | |||
<message kind="weave" text="Extending interface set for type 'test.AbstractExecutable' (AbstractExecutable.java) to include 'java.io.Serializable' (ExecutionAspect.aj)"/> | |||
<message kind="weave" text="Join point 'method-execution(void test.SubTestExecutable.execute())' in Type 'test.SubTestExecutable' (SubTestExecutable.java:6) advised by around advice from 'test.ExecutionAspect' (ExecutionAspect.aj:9)"/> | |||
<message kind="weave" text="Join point 'method-execution(void test.TestExecutable.execute())' in Type 'test.TestExecutable' (TestExecutable.java:5) advised by around advice from 'test.ExecutionAspect' (ExecutionAspect.aj:9)"/> | |||
</compile> | |||
<run class="test.SecondTestExecutable"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr171953" title="problem with itd and join point signature collection - ok"> | |||
<compile options="-1.5 -showWeaveInfo" files="test/SecondTestExecutable.java test/AbstractExecutable.java test/AnotherExecutable.java test/Executable.java test/ExecutionAspect.aj test/RunnableAspect.aj test/SubTestExecutable.java test/TestExecutable.java"> | |||
<message kind="weave" text="Join point 'method-execution(void test.SecondTestExecutable.execute())' in Type 'test.SecondTestExecutable' (SecondTestExecutable.java:5) advised by around advice from 'test.ExecutionAspect' (ExecutionAspect.aj:9)"/> | |||
<message kind="weave" text="Extending interface set for type 'test.AbstractExecutable' (AbstractExecutable.java) to include 'java.io.Serializable' (ExecutionAspect.aj)"/> | |||
<message kind="weave" text="Join point 'method-execution(void test.SubTestExecutable.execute())' in Type 'test.SubTestExecutable' (SubTestExecutable.java:6) advised by around advice from 'test.ExecutionAspect' (ExecutionAspect.aj:9)"/> | |||
<message kind="weave" text="Join point 'method-execution(void test.TestExecutable.execute())' in Type 'test.TestExecutable' (TestExecutable.java:5) advised by around advice from 'test.ExecutionAspect' (ExecutionAspect.aj:9)"/> | |||
</compile> | |||
<run class="test.SecondTestExecutable"/> | |||
</ajc-test> | |||
<ajc-test dir="bugs160/pr171952" title="generic methods and ITDs"> | |||
<compile files="Foo.java,FooAspect.java" options="-1.5"/> | |||
</ajc-test> |