diff options
author | acolyer <acolyer> | 2006-06-22 04:49:26 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2006-06-22 04:49:26 +0000 |
commit | 426cbdccfdf8fcfcda07b86d8e524d1034b2d0b7 (patch) | |
tree | 86e17625eadc66a8d7c6d908d5db6c7c746c7eec /tests/bugs152 | |
parent | 497dcf1140b7ec4eab3aab80fa5a22c8259bae48 (diff) | |
download | aspectj-426cbdccfdf8fcfcda07b86d8e524d1034b2d0b7.tar.gz aspectj-426cbdccfdf8fcfcda07b86d8e524d1034b2d0b7.zip |
tests and "fix" for pr148007 - workaround JRockit "goto" bug by generating code closer to that produced by javac when weaving after and after returning. In particular: avoid adding a goto that branches to the next instruction (now replaces that return opcode with a nop instead), and store the return value on the top of the stack in a temp before branching to the after advice dispatch and restore it afterwards.
Diffstat (limited to 'tests/bugs152')
-rw-r--r-- | tests/bugs152/pr148007/purejava/test/BooleanUnitTest.java | 71 | ||||
-rw-r--r-- | tests/bugs152/pr148007/purejava/test/LoggingAspect.java | 32 | ||||
-rw-r--r-- | tests/bugs152/pr148007/test/BooleanUnitTest.java | 62 | ||||
-rw-r--r-- | tests/bugs152/pr148007/test/LoggingAspect.aj | 17 | ||||
-rw-r--r-- | tests/bugs152/pr148007/test/TestServlet.java | 69 |
5 files changed, 251 insertions, 0 deletions
diff --git a/tests/bugs152/pr148007/purejava/test/BooleanUnitTest.java b/tests/bugs152/pr148007/purejava/test/BooleanUnitTest.java new file mode 100644 index 000000000..0d4ee3e45 --- /dev/null +++ b/tests/bugs152/pr148007/purejava/test/BooleanUnitTest.java @@ -0,0 +1,71 @@ +package test; + +/** + * Understands . . . + * + * @author Randy Stearns + */ +public class BooleanUnitTest { + + public static void main(String[] args) { + new BooleanUnitTest().test1(); + } + + public void test1() { + assertEquals("1a WRONG!", false, invert1a()); + assertEquals("1b WRONG!", true, invert1b()); + assertEquals("2 WRONG!", false, invert2()); + assertEquals("3 WRONG!", true, invert3()); + assertEquals("4 WRONG!", true, invert4()); + assertEquals("5 WRONG!", false, invert5()); + } + + private void assertEquals(String msg, boolean a, boolean b) { + if (a != b) { + throw new RuntimeException(msg); + } + } + + private boolean invert1a() { + return ! true; + } + + private boolean invert1b() { + return ! false; + } + + private boolean invert2() { + boolean ret = false; + try { + ret = ! isTrue(); + } + catch (RuntimeException t) { + LoggingAspect.aspectOf().ajc$afterReturning$test_LoggingAspect$1$188fbb36(); + throw t; + } + LoggingAspect.aspectOf().ajc$afterReturning$test_LoggingAspect$1$188fbb36(); + return ret; + } + + private boolean invert3() { + return ! isFalse(); + } + + private boolean invert4() { + boolean temp = isFalse(); + return ! temp; + } + + private boolean invert5() { + boolean temp = isTrue(); + return ! temp; + } + + private boolean isTrue() { + return true; + } + + private boolean isFalse() { + return false; + } +} diff --git a/tests/bugs152/pr148007/purejava/test/LoggingAspect.java b/tests/bugs152/pr148007/purejava/test/LoggingAspect.java new file mode 100644 index 000000000..4b265eb6d --- /dev/null +++ b/tests/bugs152/pr148007/purejava/test/LoggingAspect.java @@ -0,0 +1,32 @@ +package test; + +import org.aspectj.lang.NoAspectBoundException; + +public class LoggingAspect { + + private static LoggingAspect ajc$perSingletonInstance; + private static Throwable ajc$initFailureCause; + + static { + try { + ajc$postClinit(); + } + catch (Throwable t) { + ajc$initFailureCause = t; + } + } + + public static LoggingAspect aspectOf() { + if (ajc$perSingletonInstance == null) { + throw new NoAspectBoundException("test_LoggingAspect",ajc$initFailureCause); + } + return ajc$perSingletonInstance; + } + + public void ajc$afterReturning$test_LoggingAspect$1$188fbb36() { + } + + private static void ajc$postClinit() { + ajc$perSingletonInstance = new LoggingAspect(); + } +} diff --git a/tests/bugs152/pr148007/test/BooleanUnitTest.java b/tests/bugs152/pr148007/test/BooleanUnitTest.java new file mode 100644 index 000000000..a3b64e715 --- /dev/null +++ b/tests/bugs152/pr148007/test/BooleanUnitTest.java @@ -0,0 +1,62 @@ +package test; + +/** + * Understands . . . + * + * @author Randy Stearns + */ +public class BooleanUnitTest { + + public static void main(String[] args) { + new BooleanUnitTest().test1(); + } + + public void test1() { + assertEquals("1a WRONG!", false, invert1a()); + assertEquals("1b WRONG!", true, invert1b()); + assertEquals("2 WRONG!", false, invert2()); + assertEquals("3 WRONG!", true, invert3()); + assertEquals("4 WRONG!", true, invert4()); + assertEquals("5 WRONG!", false, invert5()); + } + + private void assertEquals(String msg, boolean a, boolean b) { + if (a != b) { + throw new RuntimeException(msg); + } + } + + private boolean invert1a() { + return ! true; + } + + private boolean invert1b() { + return ! false; + } + + private boolean invert2() { + return ! isTrue(); + } + + private boolean invert3() { + return ! isFalse(); + } + + private boolean invert4() { + boolean temp = isFalse(); + return ! temp; + } + + private boolean invert5() { + boolean temp = isTrue(); + return ! temp; + } + + private boolean isTrue() { + return true; + } + + private boolean isFalse() { + return false; + } +} diff --git a/tests/bugs152/pr148007/test/LoggingAspect.aj b/tests/bugs152/pr148007/test/LoggingAspect.aj new file mode 100644 index 000000000..ad52be82d --- /dev/null +++ b/tests/bugs152/pr148007/test/LoggingAspect.aj @@ -0,0 +1,17 @@ +package test; + +public aspect LoggingAspect { + + pointcut logPointcut() : + execution (* *(..)) + && within (test..*) + && !within(LoggingAspect); + + before() : logPointcut() { + System.out.println("entering"); + } + + after() : logPointcut() { + System.out.println("exiting"); + } +} diff --git a/tests/bugs152/pr148007/test/TestServlet.java b/tests/bugs152/pr148007/test/TestServlet.java new file mode 100644 index 000000000..b7fc8b408 --- /dev/null +++ b/tests/bugs152/pr148007/test/TestServlet.java @@ -0,0 +1,69 @@ +package test; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Hello world! + */ +public class TestServlet extends HttpServlet { + + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + booleanTest(response); + } + + private void booleanTest(HttpServletResponse response) throws ServletException { + PrintWriter out = null; + try { + out = response.getWriter(); + } catch (IOException ioe) { + throw new ServletException("Could not get writer."); + } + + out.println("Test 1a. Should be false. Was: " + invert1a()); + out.println("Test 1b. Should be true. Was: " + invert1b()); + out.println("Test 2. Should be false. Was: " + invert2()); + out.println("Test 3. Should be true. Was: " + invert3()); + out.println("Test 4. Should be true. Was: " + invert4()); + out.println("Test 5. Should be false. Was: " + invert5()); + } + + private boolean invert1a() { + return ! true; + } + + private boolean invert1b() { + return ! false; + } + + private Boolean invert2() { + return new Boolean(! isTrue()); + } + + private Boolean invert3() { + return new Boolean(! isFalse()); + } + + private boolean invert4() { + boolean temp = isFalse(); + return ! temp; + } + + private Boolean invert5() { + boolean temp = isTrue(); + return new Boolean(! temp); + } + + private boolean isTrue() { + return true; + } + + private boolean isFalse() { + return false; + } +} |