NoSuchFieldError: defaultReader when running tests in IDEA

Answered

Building a spring boot project from the gradle commandline works fine and tests run. Running a test from IDEA gives this error. Is there something about IDEA that is causing this?

java.lang.IllegalStateException: Failed to load ApplicationContext

Caused by: java.lang.NoSuchFieldError: defaultReader
    at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
    at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
    at com.jayway.jsonpath.Configuration$ConfigurationBuilder.build(Configuration.java:231)
    at org.springframework.data.web.JsonProjectingMethodInterceptorFactory.<init>(JsonProjectingMethodInterceptorFactory.java:71)
    at org.springframework.data.web.ProjectingJackson2HttpMessageConverter.initProjectionFactory(ProjectingJackson2HttpMessageConverter.java:85)
    at org.springframework.data.web.ProjectingJackson2HttpMessageConverter.<init>(ProjectingJackson2HttpMessageConverter.java:70)
    at org.springframework.data.web.config.SpringDataWebConfiguration.extendMessageConverters(SpringDataWebConfiguration.java:125)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.extendMessageConverters(WebMvcConfigurerComposite.java:143)
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.extendMessageConverters(DelegatingWebMvcConfiguration.java:122)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.getMessageConverters(WebMvcConfigurationSupport.java:718)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter(WebMvcConfigurationSupport.java:525)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration.requestMappingHandlerAdapter(WebMvcAutoConfiguration.java:376)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3a4e30d0.CGLIB$requestMappingHandlerAdapter$3(<generated>)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3a4e30d0$$FastClassBySpringCGLIB$$6eb79c3d.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$3a4e30d0.requestMappingHandlerAdapter(<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:483)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 42 more

0
8 comments
Avatar
Permanently deleted user

it happens when I use

@SpringBootTest
0

Most probably a problem with classpath. Please double-check dependencies from group "net.minidev" are imported correctly, try re-import of Gradle project.

0
Avatar
Permanently deleted user

there are no net.minidev dependencies

0
Avatar
Permanently deleted user

if I import rather open, IDEA can't do anything other than build. Every source file claims the dependencies don't exist. IDEA builds the project but the editor says no dependencies can be found. It builds from the commandline fine

0

Could you please create an issue and attach your project or minimal sample project reproducing this case? https://youtrack.jetbrains.com/issues/IDEA Thanks.

0
Avatar
Permanently deleted user

I've opened an issue. The combination of these causes the problem:

org.springframework.boot:spring-boot-starter-web
org.springframework.boot:spring-boot-starter-data-jpa
com.microsoft.azure:adal4j:1.1.1
 
 
0
Avatar
Permanently deleted user

Managed to fix it by going to Open Module Settings -> Dependencies and delete the Test dependency com.jayway.jsonpath:json-path:2.2.0

2

I hade similar issue and as removing the dependency worked only until the next reimport I checked the dependencies in detail. The issues was tehre were two net.minidivev:json-smart version in classpath, one quite old as a transitive dependency. Apparently IDEA builds classspath differently because there were no runtime issues and AFAIK this issue did not manifest on Windowws or Mac. It seems to be, for some reason, Linux-specific, although it does not make sense to me. 

0

Please sign in to leave a comment.