Dynamic SynchronizationStrategy class selection fails on Java 11
See original GitHub issueA user of our agent reported (https://github.com/elastic/apm-agent-java/issues/395) the following when running our agent on WildFly 15 with Java 11:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ByteArrayClassLoader$SynchronizationStrategy$ForJava7CapableVm to method java.lang.ClassLoader.getClassLoadingLock(java.lang.String)
WARNING: Please consider reporting this to the maintainers of co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.ByteArrayClassLoader$SynchronizationStrategy$ForJava7CapableVm
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
While I couldn’t reproduce this one (even when setting --illegal-access=debug) I debugged and saw that indeed ByteBuddy is using SynchronizationStrategy$ForJava7CapableVm, which seems to be wrong. Looks like the problem is that https://github.com/raphw/byte-buddy/blob/1107d3ffd6d390b348107c8887767cfd13f2686b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoader.java#L250 fails in Java 11 (tested with openjdk-11.0.1.13) with Method threw 'java.lang.reflect.InvocationTargetException' exception (succeeds in openjdk 10.0.2), causing https://github.com/raphw/byte-buddy/blob/1107d3ffd6d390b348107c8887767cfd13f2686b/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ByteArrayClassLoader.java#L430 to fall back to the Java 7 implementation.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)

Top Related StackOverflow Question
You are welcome. It’s fixed on master and will be part of the next release, so I am closing this. Can you use JitPack in the meantime since you are shading anyways?
What I suggested is to compile the code that has dependency on Java 7/8/whatever in a separate class and call that class through reflection only when running on the suitable Java version, so that it’s safe enough. Anyway, if there’s an easier/better way to overcome this- even better 😄 . Thanks a lot!