-
Notifications
You must be signed in to change notification settings - Fork 77
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
Blackbird doesn't work on Java 15+ #138
Comments
A colleague just hit the same issue on jdk15 (which cannot be reproduced on jdk11) which resulted in |
@jirkapinkas any chance you have a reproducer for this? |
@stevenschlansker I wonder if you have thoughts/ideas on this? Unfortunately I don't have a minimal repro yet. |
I have not experienced this exception personally, and we run blackbird on jdk16 in production with classpath (no modulepath). We also have spring and spring-boot, but that should not be relevant. I could definitely believe there's a bug, or a missed case (do you have a special classloader?) There's probably some subtle environmental or JVM configuration difference that we need to isolate. A repro is definitely best, but I appreciate it might be tricky. |
I had this issue today. This seems to be caused by Blackbird trying to serialize something that was loaded by a different classloader than Blackbird itself. I tested the serialization of an object loaded by both a parent and child classloader of the classloader that loaded Blackbird and both cases produce this error. |
Here's a self-contained minimal reproducer. package test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.blackbird.BlackbirdModule;
public class BlackbirdReproducer {
public static void main(String[] args) {
try {
var mapper = new ObjectMapper().registerModule(new BlackbirdModule());
var loader = new TestLoader(BlackbirdReproducer.class.getClassLoader());
var clazz = Class.forName("test.BlackbirdReproducer$Data", true, loader);
var constructor = clazz.getConstructor(int.class);
var data = constructor.newInstance(42);
System.out.println(mapper.writeValueAsString(data));
} catch (Exception e) {
e.printStackTrace();
}
}
public static class TestLoader extends ClassLoader {
/**
* The following class was compiled with javac to
* produce the bytecode contained in the below array
*
* public static class Data {
* private int field;
*
* public Data(int field) {
* this.field = field;
* }
*
* public int getField() {
* return field;
* }
*
* public void setField(int field) {
* this.field = field;
* }
* }
*
*/
private static int[] data = new int[]{
0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x1D, 0x0A, 0x00, 0x02, 0x00, 0x03, 0x07, 0x00, 0x04, 0x0C, 0x00, 0x05, 0x00, 0x06, 0x01, 0x00, 0x10,
0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x01, 0x00, 0x06, 0x3C, 0x69, 0x6E, 0x69, 0x74, 0x3E, 0x01,
0x00, 0x03, 0x28, 0x29, 0x56, 0x09, 0x00, 0x08, 0x00, 0x09, 0x07, 0x00, 0x0A, 0x0C, 0x00, 0x0B, 0x00, 0x0C, 0x01, 0x00, 0x1D, 0x74, 0x65, 0x73, 0x74, 0x2F,
0x42, 0x6C, 0x61, 0x63, 0x6B, 0x62, 0x69, 0x72, 0x64, 0x52, 0x65, 0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x72, 0x24, 0x44, 0x61, 0x74, 0x61, 0x01, 0x00,
0x05, 0x66, 0x69, 0x65, 0x6C, 0x64, 0x01, 0x00, 0x01, 0x49, 0x01, 0x00, 0x04, 0x28, 0x49, 0x29, 0x56, 0x01, 0x00, 0x04, 0x43, 0x6F, 0x64, 0x65, 0x01, 0x00,
0x0F, 0x4C, 0x69, 0x6E, 0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x54, 0x61, 0x62, 0x6C, 0x65, 0x01, 0x00, 0x12, 0x4C, 0x6F, 0x63, 0x61, 0x6C, 0x56, 0x61,
0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x54, 0x61, 0x62, 0x6C, 0x65, 0x01, 0x00, 0x04, 0x74, 0x68, 0x69, 0x73, 0x01, 0x00, 0x1F, 0x4C, 0x74, 0x65, 0x73, 0x74,
0x2F, 0x42, 0x6C, 0x61, 0x63, 0x6B, 0x62, 0x69, 0x72, 0x64, 0x52, 0x65, 0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x72, 0x24, 0x44, 0x61, 0x74, 0x61, 0x3B,
0x01, 0x00, 0x08, 0x67, 0x65, 0x74, 0x46, 0x69, 0x65, 0x6C, 0x64, 0x01, 0x00, 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x08, 0x73, 0x65, 0x74, 0x46, 0x69, 0x65,
0x6C, 0x64, 0x01, 0x00, 0x0A, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x46, 0x69, 0x6C, 0x65, 0x01, 0x00, 0x18, 0x42, 0x6C, 0x61, 0x63, 0x6B, 0x62, 0x69, 0x72,
0x64, 0x52, 0x65, 0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x72, 0x2E, 0x6A, 0x61, 0x76, 0x61, 0x01, 0x00, 0x08, 0x4E, 0x65, 0x73, 0x74, 0x48, 0x6F, 0x73,
0x74, 0x07, 0x00, 0x1A, 0x01, 0x00, 0x18, 0x74, 0x65, 0x73, 0x74, 0x2F, 0x42, 0x6C, 0x61, 0x63, 0x6B, 0x62, 0x69, 0x72, 0x64, 0x52, 0x65, 0x70, 0x72, 0x6F,
0x64, 0x75, 0x63, 0x65, 0x72, 0x01, 0x00, 0x0C, 0x49, 0x6E, 0x6E, 0x65, 0x72, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x65, 0x73, 0x01, 0x00, 0x04, 0x44, 0x61, 0x74,
0x61, 0x00, 0x21, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x05, 0x00,
0x0D, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x46, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0A, 0x2A, 0xB7, 0x00, 0x01, 0x2A, 0x1B, 0xB5, 0x00, 0x07,
0xB1, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x18, 0x00, 0x09, 0x00, 0x19, 0x00,
0x10, 0x00, 0x00, 0x00, 0x16, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x11, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0C, 0x00,
0x01, 0x00, 0x01, 0x00, 0x13, 0x00, 0x14, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x2A, 0xB4, 0x00,
0x07, 0xAC, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x01,
0x00, 0x00, 0x00, 0x05, 0x00, 0x11, 0x00, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15, 0x00, 0x0D, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x02,
0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x2A, 0x1B, 0xB5, 0x00, 0x07, 0xB1, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x02, 0x00, 0x00,
0x00, 0x20, 0x00, 0x05, 0x00, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x16, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x11, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x01, 0x00, 0x03, 0x00, 0x16, 0x00, 0x00, 0x00, 0x02, 0x00, 0x17, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x19,
0x00, 0x1B, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x01, 0x00, 0x08, 0x00, 0x19, 0x00, 0x1C, 0x00, 0x09
};
public TestLoader(ClassLoader parent) {
super(parent);
}
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
synchronized (getClassLoadingLock(name)) {
try {
Class<?> clazz;
if (name.equals("test.BlackbirdReproducer$Data")) {
byte[] bytes = new byte[data.length];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) data[i];
}
clazz = defineClass(name, bytes, 0, bytes.length);
} else {
clazz = super.loadClass(name, resolve);
}
if (resolve) resolveClass(clazz);
return clazz;
} catch (Exception e) {
e.printStackTrace();
throw new ClassNotFoundException("Unable to load class", e);
}
}
}
}
} |
Thank you for the test case! That should make it a lot easier to get to the bottom of this. |
@cowtowncoder , I am trying to add this test to |
I'm struggling to come up with a solution here. Any attempt to get a So far the only solution I have found is to call the custom This at least does make it work (as verified by passing the test above) but is not the easiest "end user experience". |
Yeah, compat test would be the place, although I'd need to find time to port that over to Github actions from Travis (trivial to do I know but have been too busy lately). |
I made some progress, although the solution I'm looking at right now is a bit crazy. |
Doesn't work on Java 17 also, with Jackson 2.12.4 (via Spring Boot 2.5.4) Similar Stack trace
|
We got a similar problem (Blackbird not work for us):
|
This test fails until the issue is fixed in Blackbird. FasterXML/jackson-modules-base#138
@jirkapinkas @carterkozak @Quantum64 @KENNYSOFT @dkubicki , sorry this took so long to fix, but I just posted up #162 which allows the provided test case above to pass. |
@stevenschlansker Cool! Just built the SNAPSHOT of #162 in my local and tested it. It works like a charm on Java 17, with Spring Boot 2.6.2. |
Blackbird: backport #138 to 2.13
On OpenJDK 15 & 16 Blackbird throws this exception. I don't use Module path.
java.lang.invoke.LambdaConversionException: Exception defining lambda proxy class at java.base/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:413) ~[na:na] at java.base/java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:304) ~[na:na] at java.base/java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:218) ~[na:na] at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:328) ~[na:na] at com.fasterxml.jackson.module.blackbird.ser.BBSerializerModifier.createProperty(BBSerializerModifier.java:151) ~[jackson-module-blackbird-2.12.3.jar:2.12.3] at com.fasterxml.jackson.module.blackbird.ser.BBSerializerModifier.lambda$findProperties$0(BBSerializerModifier.java:64) ~[jackson-module-blackbird-2.12.3.jar:2.12.3] at com.fasterxml.jackson.module.blackbird.util.Unchecked.lambda$runnable$0(Unchecked.java:31) ~[jackson-module-blackbird-2.12.3.jar:2.12.3] at com.fasterxml.jackson.module.blackbird.ser.BBSerializerModifier.findProperties(BBSerializerModifier.java:65) ~[jackson-module-blackbird-2.12.3.jar:2.12.3] at com.fasterxml.jackson.module.blackbird.ser.BBSerializerModifier.changeProperties(BBSerializerModifier.java:49) ~[jackson-module-blackbird-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanOrAddOnSerializer(BeanSerializerFactory.java:407) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanOrAddOnSerializer(BeanSerializerFactory.java:290) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:235) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:169) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1473) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1421) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.SerializerProvider._findExplicitUntypedSerializer(SerializerProvider.java:1390) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.hasSerializerFor(DefaultSerializerProvider.java:260) ~[jackson-databind-2.12.3.jar:2.12.3] at com.fasterxml.jackson.databind.ObjectMapper.canSerialize(ObjectMapper.java:3350) ~[jackson-databind-2.12.3.jar:2.12.3] at org.springframework.messaging.converter.MappingJackson2MessageConverter.canConvertTo(MappingJackson2MessageConverter.java:163) ~[spring-messaging-5.3.8.jar:5.3.8] at org.springframework.messaging.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:197) ~[spring-messaging-5.3.8.jar:5.3.8] at org.springframework.messaging.converter.CompositeMessageConverter.toMessage(CompositeMessageConverter.java:96) ~[spring-messaging-5.3.8.jar:5.3.8] at org.springframework.messaging.core.AbstractMessageSendingTemplate.doConvert(AbstractMessageSendingTemplate.java:181) ~[spring-messaging-5.3.8.jar:5.3.8] at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:150) ~[spring-messaging-5.3.8.jar:5.3.8] at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:129) ~[spring-messaging-5.3.8.jar:5.3.8] at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:122) ~[spring-messaging-5.3.8.jar:5.3.8] at com.company.web.controller.rest.AlarmController.publishUpdates(AlarmController.java:86) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na] at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.3.8.jar:5.3.8] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.8.jar:5.3.8] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na] at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[na:na] at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na] at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na] Caused by: java.lang.IllegalAccessException: com.company.web.pojo.AlarmWebsocketResult/com.fasterxml.jackson.module.blackbird.BlackbirdModule$$Lambda$1069/0x000000080133cd78 does not have full privilege access at java.base/java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2130) ~[na:na] at java.base/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:409) ~[na:na] ... 37 common frames omitted
The text was updated successfully, but these errors were encountered: