byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

Does bytebuddy support jdk17

Open 1057105012 opened this issue 2 years ago • 9 comments

[2022-07-25 15:46:57] [22745:rasp-logger_deamon_task] DEBUG c.x.r.i.ExceptionReportingAgentBuilderListener: onError(): { typeName=java.time .zone.ZoneRules, classLoader=null, module=module java.base, loaded=false } Execption: java.lang.IllegalArgumentException: Unsupported class file major version 61

1057105012 avatar Jul 25 '22 07:07 1057105012

Yes, but it likely needs to be updated.

raphw avatar Jul 25 '22 22:07 raphw

+1

This is our stacktrace (in https://github.com/linkedin/parseq)

java.lang.UnsupportedOperationException: Could not access Unsafe class: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
	at parseq.net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$Unavailable.initialize(ClassInjector.java:2006)
	at parseq.net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe.injectRaw(ClassInjector.java:1738)
	at parseq.net.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.inject(ClassInjector.java:110)
	at com.linkedin.parseq.lambda.ASMBasedTaskDescriptor.<clinit>(ASMBasedTaskDescriptor.java:102)

junchuanwang avatar Aug 23 '22 22:08 junchuanwang

Yes, but the ClassInjector in question does not work on Java 17 anymore. It would need to resolve another injector for this platform, such as ClassInjector.UsingUnsafe.

This is something the maintainers have to fix, it's described in the javadoc how to resolve this.

raphw avatar Aug 24 '22 14:08 raphw

it's described in the javadoc how to resolve this

Do you have a pointer to where in the javadoc it's described, or have any general advice for updating usages of bytebuddy that are encountering this error?

I saw this, but it doesn't recommend a specific alternative strategy: https://github.com/raphw/byte-buddy/blob/60f21c4e9382c794423c4d8c1b93bd508cdc80f1/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/loading/ClassLoadingStrategy.java#L113-L115

cushon avatar Sep 06 '22 20:09 cushon

It seems like the part of http://mydailyjava.blogspot.com/2018/04/jdk-11-and-proxies-in-world-past.html?m=1 about "Supporting proxies on Java versions prior to 9 and past 10" answers my question, is that still a good reference for using a ClassLoadingStrategy that works with versions before and after 9?

cushon avatar Sep 06 '22 22:09 cushon

Yes, before 9, Unsafe is the only option. From 17, handles are the only option.

raphw avatar Sep 07 '22 07:09 raphw

Most of these methods are moved to jdk.internal.misc.Unsafe which requires special access via "--add-exports" and may be some other permissions, but technically "Unsafe.defineClass" is still available.

alex-dubrouski avatar Sep 14 '22 18:09 alex-dubrouski

Byte Buddy 1.10.21 Update ASM and add support for Java 17 @raphw Would you be able to explain how add support for Java 17? Is it Java 8 compatible? AFAIK, handles does not exist in Java 8. Neither do jdk.internal.misc.Unsafe.

java.lang.UnsupportedOperationException: Could not access Unsafe class: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)

JoeJoe1989 avatar Sep 14 '22 18:09 JoeJoe1989

Byte Buddy adjusts its support based on the VM being used. You can check ClassFileVersion.ofCurrentVm() to see what Java version you are running and choose a strategy accordingly.

raphw avatar Sep 15 '22 20:09 raphw