Bug 573440

Summary: The shadowId of Shadow may not be unique.
Product: [Tools] AspectJ Reporter: Xiyou Ye <549548166>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: minor    
Priority: P3 CC: aclement
Version: 1.9.5   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:

Description Xiyou Ye CLA 2021-05-08 10:51:13 EDT
The source code of Shadow.class has pointed out that it may be a bug:

------

public abstract class Shadow {

	// every Shadow has a unique id, doesn't matter if it wraps...
	private static int nextShadowID = 100; // easier to spot than zero. // OPTIMIZE is this a bug? static?
        //....
}

------

It's quite easy to find that this code has problems in concurrency.

One more step, maybe I'm the victim of this bug?

I just built an application with Spring AOP which uses AspectJ. Randomly, the pointcut didn't work. Once happended, I have to restart the application, praying it can work, due to those caches in every layers.

I spent several hours to confirm whether the interceptor was applied correctly. Interestingly, for the same class, sometimes it is correct and sometimes it is wrong. I was stuck on this piece of code:

---

public final FuzzyBoolean match(Shadow shadow) {
		if (shadow.shadowId == lastMatchedShadowId) {
			return lastMatchedShadowResult;
		}
                //...
}

---

For some reason I couldn't know the last matched shadow. This makes the problem more complicated.

So here's my dilemma. I don't know what happened before it entered, so I can’t confirm whether the last match was itself. I found another bug, but I'm not sure if this bug may cause the confusing behavior.
Comment 1 Andrew Clement CLA 2021-05-14 18:06:29 EDT
So, you did confirm the problem was with the nextShadowId field treatment?

If you had a test project that demonstrated the issue, it would be much easier to get into (and I could potentially add a test case based on such a project).