Bug 547808 - [REGRESSION] NullpointerException thrown instead of actual exception since 1.9.3
Summary: [REGRESSION] NullpointerException thrown instead of actual exception since 1.9.3
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Runtime (show other bugs)
Version: 1.9.3   Edit
Hardware: PC Linux
: P3 major with 1 vote (vote)
Target Milestone: 1.9.5   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-31 07:26 EDT by Missing name CLA
Modified: 2019-09-26 14:22 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Missing name CLA 2019-05-31 07:26:16 EDT
This test case fails since aspectj 1.9.3 (1.9.4 also fails):
https://github.com/subes/invesdwin-aspects/blob/master/invesdwin-aspects/src/test/java/de/invesdwin/aspects/internal/AssertNoSynchronizedScheduledAspectTest.java

It works fine with aspectj 1.9.2. The expectation is that the exception thrown by the aspect arrives in the catch block. But instead a NullpointerException is thrown by aspectj without a clear stacktrace that indicates that it comes from aspectj.

This happens with openjdk 1.8.0 8u212-b03 and openjdk 13 on ubuntu, thus should not be related to a specific java version.

You can debug this directly in the linked github project as the test case should run anywhere. Just modify the supplied pom.xml to use the aspectj version you desire.

The wrong exception caused by the regression is:
java.lang.NullPointerException
	at de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean.scheduleSynchronized(AssertNoSynchronizedScheduledAspectTest.java:38)
	at de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest.testScheduled(AssertNoSynchronizedScheduledAspectTest.java:23)

The desired exception is:
java.lang.IllegalStateException: @Scheduled annotated method [public synchronized void de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean.scheduleSynchronized()] is synchronized. 
This can cause the scheduler to not trigger future schedules properly because he is blocked on a monitor. 
Please remove the synchronized modifier and use @SkipParallelExecution instead to fix this.
	at de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspect.skipExecutionIfAlreadyRunning(AssertNoSynchronizedScheduledAspect.java:24)
	at de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean.scheduleSynchronized(AssertNoSynchronizedScheduledAspectTest.java:38)
Comment 1 Andrew Clement CLA 2019-05-31 16:03:15 EDT
I wonder if it relates to https://bugs.eclipse.org/bugs/show_bug.cgi?id=333274 which I was super nervous about doing.
Comment 2 Andrew Clement CLA 2019-06-03 14:16:21 EDT
Yep, it is exactly that. I knew I didn't have enough testcases for such a serious change. However, I did previously put guards on this change so you have to doing quite a few things to trigger the problem:
- annotation style aspects
- around advice
- multiple around advices on the same thing
- advice has to be subject to closure generation (not inlining)
- one of those advice throws an exception|

From the test program you attached (super helpful, thanks!), I can see these conditions are being triggered. I can see the double advice application:

[AppClassLoader@75b84c92] weaveinfo Join point 'method-execution(void de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean.scheduleSynchronized())' in Type 'de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean' (AssertNoSynchronizedScheduledAspectTest.java:39) advised by around advice from 'de.invesdwin.aspects.internal.SkipParallelExecutionAspect' (SkipParallelExecutionAspect.java)
[AppClassLoader@75b84c92] weaveinfo Join point 'method-execution(void de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean.scheduleSynchronized())' in Type 'de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspectTest$ScheduledTestBean' (AssertNoSynchronizedScheduledAspectTest.java:39) advised by around advice from 'de.invesdwin.aspects.internal.AssertNoSynchronizedScheduledAspect' (AssertNoSynchronizedScheduledAspect.java)

I have corrected the bytecode generation for the finally block to correctly rethrow the right exception. (Also added a testcase based on what this bug shows).

All committed and pushed.

The fixes are in 1.9.5.BUILD-SNAPSHOT builds, which you can get from:

<repository>
    <id>repo.spring.io</id>
    <name>SpringSource snapshots</name>
    <url>http://repo.spring.io/snapshot</url>
</repository>
Comment 3 Missing name CLA 2019-09-20 14:41:58 EDT
When will 1.9.5 be released?
Comment 4 Missing name CLA 2019-09-26 04:58:27 EDT
Nevermind, I just renamed the 1.9.5 snapshot release to be used in the mean time.
Comment 5 Andrew Clement CLA 2019-09-26 14:22:17 EDT
Sorry, I'm so busy getting ready for Spring One Platform. I would hope for 1.9.5 in October, i still need to look at supporting latest JDK and whatever other fixes I want to roll in.