jackson-modules-base icon indicating copy to clipboard operation
jackson-modules-base copied to clipboard

IllegalAccessError with Jackson Afterburner

Open cemo opened this issue 4 years ago • 1 comments

I am using immutables v2.8.2 and jackson v2.12.3 with Afterburner module. However this is causing some issue regarding access modifers.

I created a sample project with 2 test. One of them is registering AfterBurner and other one is not. The one without afterburner is working properly. However other one is not.

https://github.com/cemo/immutable-afterburner-issue

Here is the sample error

WARNING: Disabling Afterburner serialization for class com.mycompany.app.ImmutableVal (field #0; mutator com.fasterxml.jackson.module.afterburner.ser.IntMethodPropertyWriter), due to access error (type java.lang.IllegalAccessError, message=failed to access class com.mycompany.app.ImmutableVal from class com.mycompany.app.ImmutableVal$Access4JacksonSerializer7db6db1a (com.mycompany.app.ImmutableVal is in unnamed module of loader 'app'; com.mycompany.app.ImmutableVal$Access4JacksonSerializer7db6db1a is in unnamed module of loader com.fasterxml.jackson.module.afterburner.util.MyClassLoader @5c30a9b0))

java.lang.IllegalAccessError: failed to access class com.mycompany.app.ImmutableVal from class com.mycompany.app.ImmutableVal$Access4JacksonSerializer7db6db1a (com.mycompany.app.ImmutableVal is in unnamed module of loader 'app'; com.mycompany.app.ImmutableVal$Access4JacksonSerializer7db6db1a is in unnamed module of loader com.fasterxml.jackson.module.afterburner.util.MyClassLoader @5c30a9b0)
	at com.mycompany.app.ImmutableVal$Access4JacksonSerializer7db6db1a.intGetter(com/mycompany/app/ImmutableVal$Access4JacksonSerializer.java)
	at com.fasterxml.jackson.module.afterburner.ser.IntMethodPropertyWriter.serializeAsField(IntMethodPropertyWriter.java:55)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
	at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4487)
	at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3742)
	at com.mycompany.app.AppTest.shouldAnswerWithThisTrueToo(AppTest.java:46)

I did not get why it is working without afterburner. Seems a bug to me.

cemo avatar Jun 29 '21 06:06 cemo

Sounds like you need to open up access via JPMS module definitions, or disable module restrictions for JVM. Afterburner cannot force access otherwise; nor can it do anything about it. But even with failure actual serialization should work -- message points out that optimization is disabled but the default handling should still work.

Another thing to consider might be to try the new Blackbird module instead: it is designed to work better with post-Java-8 JDKs/JVMs.

cowtowncoder avatar Jun 29 '21 19:06 cowtowncoder