paulcwarren/spring-content

NullPointerException in RestConfiguration

jdebouil opened this issue · 2 comments

Describe the bug
After migrating from spring-content 2.4.0 to 2.7.0 I experiment NPE when starting Spring Boot Application

Screenshots

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.content.commons.mappingcontext.MappingContext]: Factory method 'mappingContext' threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "internal.org.springframework.content.commons.storeservice.StoresImpl.getStores(org.springframework.content.commons.storeservice.StoreFilter)" because "this.stores" is null
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	... 98 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "internal.org.springframework.content.commons.storeservice.StoresImpl.getStores(org.springframework.content.commons.storeservice.StoreFilter)" because "this.stores" is null
	at org.springframework.content.rest.config.RestConfiguration.mappingContext(RestConfiguration.java:159)
	at org.springframework.content.rest.config.RestConfiguration$$EnhancerBySpringCGLIB$$df2e844a.CGLIB$mappingContext$2(<generated>)
	at org.springframework.content.rest.config.RestConfiguration$$EnhancerBySpringCGLIB$$df2e844a$$FastClassBySpringCGLIB$$521c56a3.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at org.springframework.content.rest.config.RestConfiguration$$EnhancerBySpringCGLIB$$df2e844a.mappingContext(<generated>)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 99 common frames omitted

Additional context
According to source code :

 @Bean
    MappingContext mappingContext() {
        MappingContext context = new MappingContext("/", ".");

        for (StoreInfo info : stores.getStores(Stores.MATCH_ALL)) {
            if (info.getDomainObjectClass() != null) {
                context.getContentProperties(info.getDomainObjectClass());
            }
        }

        return context;
    }

May be you should inject the stores by type/name ?

MappingContext mappingContext(Stores stores) {
...
}

Thanks @jdebouil. will take a look.

After upgrading to version 2.8.0, exception is no more thrown.

Thanks !