-
-
Notifications
You must be signed in to change notification settings - Fork 782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
byte-buddy no longer runs on JDK11 b6 #428
Comments
Better stack trace: |
Unsafe.defineClass has been terminally deprecated since JDK 9. For proxy classes, then maybe the user of Byte Buddy can get the class bytes and use Lookup.defineClass to inject the class (as that is the only supported API for injecting classes). |
@sdfelts In what context are you experiencing this error? This should only happen if you are using If you are using this strategy, consider replacing it with @AlanBateman Thanks for reaching out directly. Unfortunately,
There are plenty of other workarounds as of today such as using a Java agent to open the I have not too long ago summarized my thoughts about the current state of affairs, knowing most low-level libraries fairly well but did unfortunately not receive any feedback. The easiest would be to add |
This is failing in a nested call from Mockito. I'm not sure what that code is doing.
ava:94) |
Mockito is one of the cases where class file injection is still essential and no good alternative is offered. Mockito often needs to define a class within another package in order to allow mocking of package-private classes and mocking of protected methods. Without Unsafe, this is not currently possible in such a general scope. |
The current state is that byte-buddy doesn't work on JDK11 - there is no work-around because it's calling a method that doesn't exist. |
@raphw The OpenJDK mailing lists are the right place to bring up additional use-cases. The question of java agents instrumenting classes with references to auxiliary classes is something to bring to serviceability-dev as it's beyond the use-cases that the java.lang.instrument API was intended for. There may be a connection to the work in JEP 181 on nest based access control. |
@AlanBateman Is that really the right mailing list given that Mockito is more of a code testing tool and less about "debugging, profiling, monitoring, and management"? I have mentioned this topic on various OpenJDK mailing lists in the past but never got a proper response, therefore I am hesistant on using even more time on writing up my thoughts. My suggestion still is to add I find it unfortunate that this method is taken away just like that, especially with the wide use of Java agents that currently rely on this method to implement javac-like behavior and the large amount of testing tools such as Mockito that are now broken. Right now, Mockito does not work at all and the only idea I have is to use the mentioned Java agent to overcome this what would just imply more hacks that break in the future. With only these two methods, I do not think Of course, to a given extend, we could use the lookup API but this will not work in many scenarios such as OSGi. I think it is legitimate that some libraries need to get around this. |
I have created https://bugs.openjdk.java.net/browse/JDK-8200559 to provide a replacement API for Unsafe::defineClass for java instrumentation agent. |
Brilliant, adding this method would solve 99% of my use cases and avoid the ugly workaround via jdk.internal.misc. It also seems like using MethodHandles.Lookup::defineClass works for the majority of our use cases besides some obscure ones involving serialization which I doubt that those impact too many users. I will try to get a release out asap and ask for some community feedback on the changes. |
Build does now work again. Mockito is also fixed. |
Unsafe.defineClass was removed.
Caused by:
java.lang.UnsupportedOperationException: Cannot define class using
reflection
at
net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Unavail
able.defineClass(ClassInjec
tor.java:821)
at
net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInject
or.java:185)
The quick fix to get a running jar again is to remove the JDK9 logic in src/main/java/net/bytebuddy/dynamic/loading/ClassInjector.java
@@ -9,7 +9,6 @@ import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.implementation.MethodCall;
-import net.bytebuddy.utility.JavaModule;
import net.bytebuddy.utility.JavaType;
import net.bytebuddy.utility.RandomString;
import org.objectweb.asm.Opcodes;
@@ -298,9 +297,10 @@ public interface ClassInjector {
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION",
justification = "Exception should not be rethrown but trigger a fallback")
public Initializable run() {
try {
The text was updated successfully, but these errors were encountered: