Problem with afterburner module with new field added serialVersionUID
shankyty opened this issue · 4 comments
I am getting below problem after I have added private final long serialVersionUID in asbtract class foobarAbstract which is extended by MyClass
//code register afterburner module
objectMapper.registerModule(new AfterburnerModule()); version 2.7.1
It logs warning
WARNING: Disabling Afterburner serialization for class com.foobar.commons.impl.MyClass (field #0; muator com.fasterxml.jackson.module.afterburner.ser.LongFieldPropertyWriter), due to access error (type java.lang.IllegalAccessError, message=tried to access field class com.foobar.commons.impl.MyClass.serialVersionUID from class class com.foobar.commons.impl.MyClass$Access4JacksonDeserializerfb8b0dbb)
It and then throws error
java.lang.IllegalAccessError: tried to access field class com.foobar.commons.impl.MyClass.serialVersionUID from class com.foobar.commons.impl.MyClass$Access4JacksonDeserializerfb8b0dbb
at com.foobar.commons.impl.MyClass$Access4JacksonDeserializerfb8b0dbb.longField(com/xxx/commons/impl/Myclass$Access4JacksonDeserializer.java)
at com.fasterxml.jackson.module.afterburner.ser.LongFieldPropertyWriter.serializeAsField(LongFieldPropertyWriter.java:55)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:678)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:2436)
at com.fasterxml.jackson.databind.ObjectMapper.valueToTree(ObjectMapper.java:2568)
at com.foobar.module.DynamicSerTest.ser_test(DynamicSerTest.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
First things first: serialVersionUID
should always be static
field, not member. So I think that's something you should change; otherwise it's not used by JDK serialization at all.
But I would still be interested in seeing the class in question: no such exception should be thrown. I have not seen this occur, and there are tests for long
fields, so I'd need to see exactly how it occurs.
Abstract class with serialVersion field
abstract class FooBar{
final long serialVersionUID = 1L;
public void medthod();
...
}
Ands its implementation
public class Myclass extends FooBar{
... lots of field and methods
}
Also just figured out if I run test within intellij it works , but with maven clean install it throws error
@shankyty Are the classes in same Java package or different ones? (this affects visibility rules by class loader)
They are in different packages,
com.foo.bar,abc and com.foo.bar.xyz,
But I am still confused why it is working , when I am executing it from intellij but giveing error while executing from maven.