From bfeb9d2fc30aee8352b3f41d5996530fbffa58d0 Mon Sep 17 00:00:00 2001 From: Robin Johri Date: Wed, 23 Sep 2026 16:23:54 +0530 Subject: [PATCH] Add regression test for handler(Exception+) advice woven into catch(Exception|LinkageError) multi-catch (#368) Weaving handler(Exception+) advice into a Java 7+ multi-catch clause that mixes an Exception subtype with a non-Exception Throwable subtype (e.g. catch (Exception | LinkageError e)) used to produce invalid bytecode: the caught variable's compile-time type is the least-upper-bound Throwable, not Exception, and the woven advice-dispatch code passed it on without a checkcast, causing a VerifyError at class-load time. This was already fixed silently between 1.9.21.1 and 1.9.21.2 (no release notes entry, no test coverage), so this adds a load-time-weaving regression test to guard the fixed behaviour against future regressions. Fixes #368 Co-Authored-By: Claude Sonnet 5 --- tests/bugs1925/github_368/Application.java | 15 +++++++++++++++ tests/bugs1925/github_368/LoggingAspect.java | 12 ++++++++++++ tests/bugs1925/github_368/Worker.java | 15 +++++++++++++++ tests/bugs1925/github_368/ant.xml | 11 +++++++++++ tests/bugs1925/github_368/aop.xml | 5 +++++ .../aspectj/systemtest/ajc1925/Bugs1925Tests.java | 4 ++++ .../org/aspectj/systemtest/ajc1925/ajc1925.xml | 8 ++++++++ 7 files changed, 70 insertions(+) create mode 100644 tests/bugs1925/github_368/Application.java create mode 100644 tests/bugs1925/github_368/LoggingAspect.java create mode 100644 tests/bugs1925/github_368/Worker.java create mode 100644 tests/bugs1925/github_368/ant.xml create mode 100644 tests/bugs1925/github_368/aop.xml diff --git a/tests/bugs1925/github_368/Application.java b/tests/bugs1925/github_368/Application.java new file mode 100644 index 000000000..0c37c05ea --- /dev/null +++ b/tests/bugs1925/github_368/Application.java @@ -0,0 +1,15 @@ +/** + * https://github.com/eclipse-aspectj/aspectj/issues/368 + * + * Regression test: weaving handler(Exception+) advice into a catch clause that + * multi-catches an Exception subtype together with a non-Exception Throwable + * subtype (e.g. "catch (Exception | LinkageError e)") used to produce a + * VerifyError, because the caught variable's compile-time type in that case is + * the least-upper-bound java.lang.Throwable, not Exception, and the woven + * advice-dispatch code passed it on without a checkcast. Fixed since 1.9.21.2. + */ +public class Application { + public static void main(String[] args) throws Exception { + new Worker().doWork(); + } +} diff --git a/tests/bugs1925/github_368/LoggingAspect.java b/tests/bugs1925/github_368/LoggingAspect.java new file mode 100644 index 000000000..8e1db9e31 --- /dev/null +++ b/tests/bugs1925/github_368/LoggingAspect.java @@ -0,0 +1,12 @@ +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; + +@Aspect +public class LoggingAspect { + + @Before("handler(Exception+) && args(ex)") + public void handle(JoinPoint jp, Exception ex) { + System.out.println("advice fired for " + ex); + } +} diff --git a/tests/bugs1925/github_368/Worker.java b/tests/bugs1925/github_368/Worker.java new file mode 100644 index 000000000..af0a304a7 --- /dev/null +++ b/tests/bugs1925/github_368/Worker.java @@ -0,0 +1,15 @@ +public class Worker { + + public void doWork() throws Exception { + try { + riskyCall(); + } + catch (Exception | LinkageError e) { + System.out.println("handled: " + e); + } + } + + private void riskyCall() throws Exception { + throw new IllegalStateException("boom"); + } +} diff --git a/tests/bugs1925/github_368/ant.xml b/tests/bugs1925/github_368/ant.xml new file mode 100644 index 000000000..dfc1d679a --- /dev/null +++ b/tests/bugs1925/github_368/ant.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tests/bugs1925/github_368/aop.xml b/tests/bugs1925/github_368/aop.xml new file mode 100644 index 000000000..e018b520d --- /dev/null +++ b/tests/bugs1925/github_368/aop.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1925/Bugs1925Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1925/Bugs1925Tests.java index 3acdfec86..4606aa2af 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1925/Bugs1925Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1925/Bugs1925Tests.java @@ -51,6 +51,10 @@ public void testGh344_PerthisInModule() { runTest("perthis aspect in module"); } + public void testGh368_HandlerAdviceMultiCatchExceptionLinkageError() { + runTest("handler advice woven into multi-catch(Exception|LinkageError)"); + } + @Override protected java.net.URL getSpecFile() { return getClassResource("ajc1925.xml"); diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1925/ajc1925.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1925/ajc1925.xml index 303ac7fe7..586e8941a 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc1925/ajc1925.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1925/ajc1925.xml @@ -158,4 +158,12 @@ JDK 25 (https://openjdk.org/projects/jdk/25/): + + + + + + + +