Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/bugs1925/github_368/Application.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
12 changes: 12 additions & 0 deletions tests/bugs1925/github_368/LoggingAspect.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
15 changes: 15 additions & 0 deletions tests/bugs1925/github_368/Worker.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
11 changes: 11 additions & 0 deletions tests/bugs1925/github_368/ant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- ajc-ant script, not to be used from Ant commant line - see AntSpec -->
<project name="ltw">
<target name="handler advice woven into multi-catch(Exception|LinkageError)">
<copy file="${aj.root}/tests/bugs1925/github_368/aop.xml" tofile="${aj.sandbox}/META-INF/aop.xml"/>
<java fork="yes" classname="Application" failonerror="yes">
<classpath refid="aj.path"/>
<jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
</java>
</target>

</project>
5 changes: 5 additions & 0 deletions tests/bugs1925/github_368/aop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<aspectj>
<aspects>
<aspect name="LoggingAspect"/>
</aspects>
</aspectj>
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,12 @@ JDK 25 (https://openjdk.org/projects/jdk/25/):
</run>
</ajc-test>

<!-- https://github.com/eclipse-aspectj/aspectj/issues/368 -->
<ajc-test dir="bugs1925/github_368" vm="8" title="handler advice woven into multi-catch(Exception|LinkageError)">
<compile files="Worker.java Application.java" options="-8"/>
<compile files="LoggingAspect.java" options="-8 -Xlint:ignore"/>
<!-- Reproduces only under load-time weaving in a forked JVM with a java agent, hence Ant build -->
<ant file="ant.xml" target="handler advice woven into multi-catch(Exception|LinkageError)" verbose="true"/>
</ajc-test>

</suite>