spring-projects / spring-projects/spring-data-rest

Scala Map considered a PersistentEntity causing NullPointerException in UriToEntityConverter [DATAREST-857]

Open
#1,228 7 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Abhijit Sarkar opened DATAREST-857 and commented

I'm converting a pet project from Java to Scala. It uses the following frameworks:

  • Spring Boot
  • Spring HATEOAS
  • Spring Data Rest
  • Spring Data MongoDB
  • Embedded MongoDB

I hit a wall with that at startup. org.springframework.data.rest.core.UriToEntityConverter constructor tries to look up an entry previous stored in field persistentEntities of class org.springframework.data.mapping.context.AbstractMappingContext with key as follows:

org.springframework.data.util.ParameterizedTypeInformation
--- resolvedType: scala.collection.immutable.Map
--- typeArguments: java.lang.String,java.lang.String

UriToEntityConverter loses the type info and just looks up by raw type scala.collection.immutable.Map, thus not finding the entry. It then, without checking for null, does a hasIdProperty and blows up in pieces.

The code is available here on branch feign-scala-boot. The integration test FeignSpecP1 is the one that fails.

Stacktrace:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.DefaultFormattingConversionService]: Factory method 'defaultConversionService' threw exception; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 107 more
Caused by: java.lang.NullPointerException
	at org.springframework.data.rest.core.UriToEntityConverter.<init>(UriToEntityConverter.java:68)
	at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.uriToEntityConverter(RepositoryRestMvcConfiguration.java:593)
	at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.defaultConversionService(RepositoryRestMvcConfiguration.java:209)
	at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$c2974a83.CGLIB$defaultConversionService$51(<generated>)
	at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$c2974a83$$FastClassBySpringCGLIB$$334e15b3.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.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$c2974a83.defaultConversionService(<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:497)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 108 more

Affects: 2.4.4 (Gosling SR4)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.