Bug 537825 - Compliance with Java 9 and later
Summary: Compliance with Java 9 and later
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.9.1   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: 1.9.2   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-09 08:04 EDT by Chris Gaudry CLA
Modified: 2018-08-24 21:00 EDT (History)
1 user (show)

See Also:


Attachments
Java 9+ compliancy (2.70 KB, application/octet-stream)
2018-08-09 08:04 EDT, Chris Gaudry CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Gaudry CLA 2018-08-09 08:04:03 EDT
Created attachment 275334 [details]
Java 9+ compliancy

Hello,

Weaving a jar file using AspectJ v1.9.1, under Java 9 and 10, generates the following code:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.NoAspectBoundException;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.runtime.internal.CFlowStack;
...

@Aspect
public class MyClass {
	private static final Log A_LOG;
	private static /* synthetic */ Throwable ajc$initFailureCause;
	public static /* synthetic */ MyClass ajc$perSingletonInstance;
	public static final /* synthetic */ CFlowStack ajc$cflowStack$0;

	static {
		MyClass.ajc$preClinit();
		try {
			A_LOG = LogFactory.getLog(MyClass.class);
			MyClass.ajc$postClinit();
		}
		catch (Throwable throwable) {
			ajc$initFailureCause = throwable;
		}
	}

...

	public static boolean hasAspect() {
		if (ajc$perSingletonInstance != null) {
			return true;
		}
		return false;
	}

	private static /* synthetic */ void ajc$postClinit() {
		ajc$perSingletonInstance = new MyClass();
	}

	private static /* synthetic */ void ajc$preClinit() {
		ajc$cflowStack$0 = new CFlowStack();
	}
}


The execution of this code, under Java 9 and 10, generates the following execption:

java.util.concurrent.ExecutionException: java.lang.IllegalAccessError: Update to static final field MyClass.ajc$cflowStack$0 attempted from a different method (ajc$preClinit) than the initializer method <clinit> 
	...
Caused by: java.lang.IllegalAccessError: Update to static final field MyClass.ajc$cflowStack$0 attempted from a different method (ajc$preClinit) than the initializer method <clinit> 
	at MyClass.ajc$preClinit(MyClass.aj:1) ~[myjar-aop.jar:w.x.y-z]
	at MyClass.<clinit>(MyClass.aj) ~[myjar-aop.jar:w.x.y-z]
	... 1 more

I have successfully tried to patch the sources of AspectJ so that I can move forward in my work.
For your information, I added my patch attachment.

Could you please take a look at this problem so that AspectJ complies with the specifications of Java 9 and above, concerning the initialization of the "static final" class attributes?

Thanks in advance.
Comment 1 Andrew Clement CLA 2018-08-24 21:00:53 EDT
All fixed up! Should have been caught when fixing this situation for the joinpoint objects, same fix here. Thanks for catching it. I guess will become a real issue when folks move from between LTS versions (8>11).