Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jackson throws IllegalAccessError even with the same versions

I'm developing a software with jackson, but totally get stuck... When I run the spring-boot program with java -jar <MY_APPLICATION>.jar command, I got the following error:

...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'jacksonObjectMapper' threw exception; nested exception is
java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 84 more
Caused by: java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
        at com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.<init>(JavaTimeModule.java:159)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:78)
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:719)
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:572)
        at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:554)
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration.jacksonObjectMapper(JacksonAutoConfiguration.java:87)
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$2434a0bb.CGLIB$jacksonObjectMapper$0(<generated>)
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$2434a0bb$$FastClassBySpringCGLIB$$d685921f.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
        at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$2434a0bb.jacksonObjectMapper(<generated>)
        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.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 85 more

There are more error messages above the error, but I think the important message is java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;), which I know it cannot happen generally.

I confirmed that the jackson modules are in the same version(2.6.5 which comes from spring-boot's dependency), and codehaus's jackson is not included:

$ mvn dependency:tree -Dverbose -Dincluces=com.fasterxml.jackson.core | grep -v omitted

...

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ patriot-fdc-web ---
[INFO] <MY_GROUP>:<MY_APPLICATION_A>:war:0.3.9-SNAPSHOT
[INFO] +- <MY_GROUP>:<MY_APPLICATION_B>:jar:0.3.9-SNAPSHOT:compile
[INFO] |  \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.6.5:compile
[INFO] |     +- com.fasterxml.jackson.core:jackson-core:jar:2.6.5:compile
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:1.3.3.RELEASE:compile
[INFO]    \- com.fasterxml.jackson.core:jackson-databind:jar:2.6.5:compile (version managed from 2.4.2)
[INFO]       +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.5:compile (version managed from 2.6.0)

Can anybody encounter such a problem? Anyone can suggest any solution or possibility for the error? Thank you in advance.

like image 235
tsuda7 Avatar asked Mar 01 '17 07:03

tsuda7


2 Answers

I've found the cause.

The dependency included calcite-avartica artifact, and it has a shaded jackson in it with version 2.1.1. That's why I cannot find the dependency by mvn dependency:tree. I found it through debugging remotely by seeing where StdSerializer came from. https://issues.apache.org/jira/browse/CALCITE-1110

Avartica 1.9.0 or later might not bother us. I just excluded calcite-core and calcite-avartica and finally it worked fine.

like image 149
tsuda7 Avatar answered Nov 14 '22 21:11

tsuda7


Had a similar issue in sbt, the fix was also to remove calcita-core and calcite-avatica like so

ExclusionRule(organization = "org.apache.calcite", name = "calcite-core"),
ExclusionRule(organization = "org.apache.calcite", name = "calcite-avatica")
like image 20
Raul Avatar answered Nov 14 '22 22:11

Raul