Summary: | java.lang.IllegalAccessError: Update to static final field attempted from a different method (ajc$preClinit1) than the initializer method <clinit> | ||
---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | Mikael Petterson <mikaelpetterson> |
Component: | Runtime | Assignee: | aspectj inbox <aspectj-inbox> |
Status: | NEW --- | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | aclement, ning.n.zhang |
Version: | 1.9.5 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All | ||
Whiteboard: |
Description
Mikael Petterson
2020-03-31 02:04:45 EDT
The component should be compile. I tried to reproduce it locally, reproduce it from one Enum. Orginal Enum: ``` public enum ExampleEnum { ENUM1, EMUM2; public static String getAnotherName(ExampleEnum arg) { return arg.name() + "_" + AspectUtil.getDeprecatedResult(); } } ``` After AspectJ compile: ``` public enum ExampleEnum { ENUM1, EMUM2; static { ajc$preClinit(); } private static final long serialVersionUID; public static String getAnotherName(ExampleEnum arg) { if (DeprecatedMethodsAspect.ajc$if$a6adfc1()) DeprecatedMethodsAspect.aspectOf().ajc$before$com_ericsson_commonlibrary_statisticscollectorframework_aspectj_DeprecatedMethodsAspect$1$b9499fc0(Factory.makeJP(ajc$tjp_0, null, null)); return String.valueOf(arg.name()) + "_" + AspectUtil.getDeprecatedResult(); } } ``` This strange serialVersionUID is generated. It only happens on Java11, can not generate on Java8. The control for AspectJ to generate serialVersionUID is -XaddSerialVersionUID - you aren't setting that somewhere are you? Andrew, you are right. serialVersionUID is generated -XaddSerialVersionUID. So I think it is runtime issue now. I did more comparisons, generated class with both compliance level 8 & 11, after decompile, find both have below: static { ajc$preClinit(); } private static final long serialVersionUID; But find runtime errors with compliance level 11. 1. Compliance level 8, run successfully on both JRE8 and JRE11. 2. Compliance level 11, met issue same as Mikael mentioned: can not update serialVersionUID during class initialization. So the workaround is (unfortunately) don't set -XaddSerialVersionUID. The only real way to fix this I think is inline the serial version code into the actual clinit, but at the same time mark it some way so that the code doesn't become a candidate for join point shadows that might match a pointcut. Checking the docs I see it says "Causes the compiler to calculate and add the SerialVersionUID field to any type implementing Serializable that is affected by an aspect. " - is it perhaps adding it to too many types I wonder? Worth me checking... Just looked and tested it and indeed it will only do it if they are Serializable, not any class. |