From f6a1fdb8ae87846f964d21ad6df57941b577a1ce Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 2 Mar 2007 08:24:04 +0000 Subject: [PATCH] integrated head into extensions branch --- .../pr171953/test/AbstractExecutable.java | 5 + .../pr171953/test/AnotherExecutable.java | 5 + tests/bugs160/pr171953/test/Executable.java | 6 + .../bugs160/pr171953/test/ExecutionAspect.aj | 12 ++ tests/bugs160/pr171953/test/RunnableAspect.aj | 11 ++ .../pr171953/test/SecondTestExecutable.java | 13 ++ .../pr171953/test/SubTestExecutable.java | 9 ++ .../bugs160/pr171953/test/TestExecutable.java | 7 ++ .../pr171953_2/test/AbstractProcessor.java | 5 + .../bugs160/pr171953_2/test/ListFactory.java | 9 ++ .../pr171953_2/test/ListFactoryAspect.aj | 30 +++++ .../pr171953_2/test/ListFactoryConsumer.java | 6 + tests/bugs160/pr171953_2/test/Processor.java | 5 + .../test/SimpleListFactoryConsumer.java | 16 +++ tests/bugs160/pr174449/Foo.java | 33 +++++ tests/bugs160/pr175806/A.java | 12 ++ .../systemtest/ajc160/Ajc160Tests.java | 116 +++++++++++++++++- .../org/aspectj/systemtest/ajc160/ajc160.xml | 54 ++++++++ 18 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 tests/bugs160/pr171953/test/AbstractExecutable.java create mode 100644 tests/bugs160/pr171953/test/AnotherExecutable.java create mode 100644 tests/bugs160/pr171953/test/Executable.java create mode 100644 tests/bugs160/pr171953/test/ExecutionAspect.aj create mode 100644 tests/bugs160/pr171953/test/RunnableAspect.aj create mode 100644 tests/bugs160/pr171953/test/SecondTestExecutable.java create mode 100644 tests/bugs160/pr171953/test/SubTestExecutable.java create mode 100644 tests/bugs160/pr171953/test/TestExecutable.java create mode 100644 tests/bugs160/pr171953_2/test/AbstractProcessor.java create mode 100644 tests/bugs160/pr171953_2/test/ListFactory.java create mode 100644 tests/bugs160/pr171953_2/test/ListFactoryAspect.aj create mode 100644 tests/bugs160/pr171953_2/test/ListFactoryConsumer.java create mode 100644 tests/bugs160/pr171953_2/test/Processor.java create mode 100644 tests/bugs160/pr171953_2/test/SimpleListFactoryConsumer.java create mode 100644 tests/bugs160/pr174449/Foo.java create mode 100644 tests/bugs160/pr175806/A.java diff --git a/tests/bugs160/pr171953/test/AbstractExecutable.java b/tests/bugs160/pr171953/test/AbstractExecutable.java new file mode 100644 index 000000000..6d9f880a6 --- /dev/null +++ b/tests/bugs160/pr171953/test/AbstractExecutable.java @@ -0,0 +1,5 @@ +package test; + +public abstract class AbstractExecutable implements AnotherExecutable { + +} diff --git a/tests/bugs160/pr171953/test/AnotherExecutable.java b/tests/bugs160/pr171953/test/AnotherExecutable.java new file mode 100644 index 000000000..75103a696 --- /dev/null +++ b/tests/bugs160/pr171953/test/AnotherExecutable.java @@ -0,0 +1,5 @@ +package test; + +public interface AnotherExecutable extends Executable { + +} diff --git a/tests/bugs160/pr171953/test/Executable.java b/tests/bugs160/pr171953/test/Executable.java new file mode 100644 index 000000000..13cb945b1 --- /dev/null +++ b/tests/bugs160/pr171953/test/Executable.java @@ -0,0 +1,6 @@ +package test; + +public interface Executable { + + void execute(); +} diff --git a/tests/bugs160/pr171953/test/ExecutionAspect.aj b/tests/bugs160/pr171953/test/ExecutionAspect.aj new file mode 100644 index 000000000..1dd0266d8 --- /dev/null +++ b/tests/bugs160/pr171953/test/ExecutionAspect.aj @@ -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); + } +} diff --git a/tests/bugs160/pr171953/test/RunnableAspect.aj b/tests/bugs160/pr171953/test/RunnableAspect.aj new file mode 100644 index 000000000..fa12b7b99 --- /dev/null +++ b/tests/bugs160/pr171953/test/RunnableAspect.aj @@ -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; +} diff --git a/tests/bugs160/pr171953/test/SecondTestExecutable.java b/tests/bugs160/pr171953/test/SecondTestExecutable.java new file mode 100644 index 000000000..1743a9728 --- /dev/null +++ b/tests/bugs160/pr171953/test/SecondTestExecutable.java @@ -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(); + } +} diff --git a/tests/bugs160/pr171953/test/SubTestExecutable.java b/tests/bugs160/pr171953/test/SubTestExecutable.java new file mode 100644 index 000000000..8dd83bd03 --- /dev/null +++ b/tests/bugs160/pr171953/test/SubTestExecutable.java @@ -0,0 +1,9 @@ +package test; + +public class SubTestExecutable extends TestExecutable { + + @Override + public void execute() { + super.execute(); + } +} diff --git a/tests/bugs160/pr171953/test/TestExecutable.java b/tests/bugs160/pr171953/test/TestExecutable.java new file mode 100644 index 000000000..bfd296a2d --- /dev/null +++ b/tests/bugs160/pr171953/test/TestExecutable.java @@ -0,0 +1,7 @@ +package test; + +public class TestExecutable implements Executable { + + public void execute() { + } +} diff --git a/tests/bugs160/pr171953_2/test/AbstractProcessor.java b/tests/bugs160/pr171953_2/test/AbstractProcessor.java new file mode 100644 index 000000000..008fba159 --- /dev/null +++ b/tests/bugs160/pr171953_2/test/AbstractProcessor.java @@ -0,0 +1,5 @@ +package test; + +public abstract class AbstractProcessor implements Processor { + +} diff --git a/tests/bugs160/pr171953_2/test/ListFactory.java b/tests/bugs160/pr171953_2/test/ListFactory.java new file mode 100644 index 000000000..473ccac20 --- /dev/null +++ b/tests/bugs160/pr171953_2/test/ListFactory.java @@ -0,0 +1,9 @@ +package test; + +import java.util.List; + +public interface ListFactory { + + List createList(); + List createList(int initialCapacity); +} diff --git a/tests/bugs160/pr171953_2/test/ListFactoryAspect.aj b/tests/bugs160/pr171953_2/test/ListFactoryAspect.aj new file mode 100644 index 000000000..acfc27e70 --- /dev/null +++ b/tests/bugs160/pr171953_2/test/ListFactoryAspect.aj @@ -0,0 +1,30 @@ +package test; + +import java.util.ArrayList; +import java.util.List; + +public aspect ListFactoryAspect { + + private ListFactory listFactory = new ListFactory() { + public List createList() { + return new ArrayList(); + }; + public List createList(int initialCapacity) { + return new ArrayList(); + }; + }; + + declare parents: Processor implements ListFactoryConsumer; + + public ListFactory ListFactoryConsumer.getListFactory() { + return ListFactoryAspect.aspectOf().listFactory; + } + + public List ListFactoryConsumer.createList() { + return getListFactory().createList(); + } + + public List ListFactoryConsumer.createList(int initialCapacity) { + return getListFactory().createList(initialCapacity); + } +} diff --git a/tests/bugs160/pr171953_2/test/ListFactoryConsumer.java b/tests/bugs160/pr171953_2/test/ListFactoryConsumer.java new file mode 100644 index 000000000..41747d902 --- /dev/null +++ b/tests/bugs160/pr171953_2/test/ListFactoryConsumer.java @@ -0,0 +1,6 @@ +package test; + +public interface ListFactoryConsumer { + + ListFactory getListFactory(); +} diff --git a/tests/bugs160/pr171953_2/test/Processor.java b/tests/bugs160/pr171953_2/test/Processor.java new file mode 100644 index 000000000..c76cdaaf9 --- /dev/null +++ b/tests/bugs160/pr171953_2/test/Processor.java @@ -0,0 +1,5 @@ +package test; + +public interface Processor { + +} diff --git a/tests/bugs160/pr171953_2/test/SimpleListFactoryConsumer.java b/tests/bugs160/pr171953_2/test/SimpleListFactoryConsumer.java new file mode 100644 index 000000000..ab1ec7cf7 --- /dev/null +++ b/tests/bugs160/pr171953_2/test/SimpleListFactoryConsumer.java @@ -0,0 +1,16 @@ +package test; + +import java.util.ArrayList; +import java.util.List; + +public class SimpleListFactoryConsumer extends AbstractProcessor { + + public void run() { + //List> list1 = getListFactory().createList(); + List> list2 = this.createList(); + } + + public static void main(String[] args) { + new SimpleListFactoryConsumer().run(); + } +} diff --git a/tests/bugs160/pr174449/Foo.java b/tests/bugs160/pr174449/Foo.java new file mode 100644 index 000000000..68a400d7d --- /dev/null +++ b/tests/bugs160/pr174449/Foo.java @@ -0,0 +1,33 @@ +abstract aspect Replicate { + + 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 { + protected pointcut broadcast(Boo servant) : call(* *.setScene(..)) && target(servant); +} + +aspect ReplicateConcreteG extends Replicate { + 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() {} +} diff --git a/tests/bugs160/pr175806/A.java b/tests/bugs160/pr175806/A.java new file mode 100644 index 000000000..562276c39 --- /dev/null +++ b/tests/bugs160/pr175806/A.java @@ -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); + } + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java b/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java index 79dfe4c18..fc816e0b9 100644 --- a/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc160/Ajc160Tests.java @@ -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); + } } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml b/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml index bdca3440d..229027f5f 100644 --- a/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml +++ b/tests/src/org/aspectj/systemtest/ajc160/ajc160.xml @@ -5,6 +5,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5