java.lang.NullPointerException

Spring JIRA | Petar Tahchiev | 3 years ago
  1. 0

    Hi guys, I'm testing the 2.0-SNAPSHOT version and it all works great, except for one scenario. I open one of my jpa entities with the following URL: {code} http://localhost:8111/rest/category/845065653710592 {code} and it's all displayed good. Then I decide to follow one of the links there: {code} http://localhost:8111/rest/category/845065653710592/picture {code} and it throws a null-point exception: {code} 2013-09-29 01:07:30.076:WARN:oejs.ServletHandler:/rest/category/845065653710592/picture java.lang.NullPointerException at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.getSelfLinkFor(PersistentEntityResourceAssembler.java:68) at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:59) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$1.apply(RepositoryPropertyReferenceController.java:138) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$1.apply(RepositoryPropertyReferenceController.java:107) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.doWithReferencedProperty(RepositoryPropertyReferenceController.java:460) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(RepositoryPropertyReferenceController.java:145) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:735) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1448) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419) {code} The reason is because in PersistentEntityResourceAssembler:68 we see the following: {code} Object id = wrapper.getProperty(entity.getIdProperty()); {code} and in my case entity is NULL. Why is it null? Because a couple of lines before that you get the class of the entity like this: {code} PersistentEntity<?, ?> entity = repositories.getPersistentEntity(instance.getClass()); {code} and since the instance is lazy loaded, so instance.getClass() returns the proxy class: {code} class com.xxxxxxxxx.media.MediaModel_$$_javassist_33 {code} and this is not a valid entity so repositories object returns null.

    Spring JIRA | 3 years ago | Petar Tahchiev
    java.lang.NullPointerException
  2. 0

    Hi guys, I'm testing the 2.0-SNAPSHOT version and it all works great, except for one scenario. I open one of my jpa entities with the following URL: {code} http://localhost:8111/rest/category/845065653710592 {code} and it's all displayed good. Then I decide to follow one of the links there: {code} http://localhost:8111/rest/category/845065653710592/picture {code} and it throws a null-point exception: {code} 2013-09-29 01:07:30.076:WARN:oejs.ServletHandler:/rest/category/845065653710592/picture java.lang.NullPointerException at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.getSelfLinkFor(PersistentEntityResourceAssembler.java:68) at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:59) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$1.apply(RepositoryPropertyReferenceController.java:138) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$1.apply(RepositoryPropertyReferenceController.java:107) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.doWithReferencedProperty(RepositoryPropertyReferenceController.java:460) at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(RepositoryPropertyReferenceController.java:145) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:735) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1448) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419) {code} The reason is because in PersistentEntityResourceAssembler:68 we see the following: {code} Object id = wrapper.getProperty(entity.getIdProperty()); {code} and in my case entity is NULL. Why is it null? Because a couple of lines before that you get the class of the entity like this: {code} PersistentEntity<?, ?> entity = repositories.getPersistentEntity(instance.getClass()); {code} and since the instance is lazy loaded, so instance.getClass() returns the proxy class: {code} class com.xxxxxxxxx.media.MediaModel_$$_javassist_33 {code} and this is not a valid entity so repositories object returns null.

    Spring JIRA | 3 years ago | Petar Tahchiev
    java.lang.NullPointerException
  3. 0

    Android: Saving Map State in Google map

    Stack Overflow | 11 months ago | Junie Negentien
    java.lang.RuntimeException: Unable to resume activity {com.ourThesis.junieNegentien2015/com.ourThesis.junieNegentien2015.MainActivity}: java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.getSelfLinkFor()
    2. Spring Data REST - WebMVC
      RepositoryPropertyReferenceController.followPropertyReference
      1. org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.getSelfLinkFor(PersistentEntityResourceAssembler.java:68)
      2. org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:59)
      3. org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$1.apply(RepositoryPropertyReferenceController.java:138)
      4. org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$1.apply(RepositoryPropertyReferenceController.java:107)
      5. org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.doWithReferencedProperty(RepositoryPropertyReferenceController.java:460)
      6. org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(RepositoryPropertyReferenceController.java:145)
      6 frames
    3. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:601)
      4 frames
    4. Spring
      InvocableHandlerMethod.invokeForRequest
      1. org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      2. org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      2 frames
    5. Spring MVC
      FrameworkServlet.doGet
      1. org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      2. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
      3. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
      4. org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      5. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      6. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      7. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
      8. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
      8 frames
    6. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
      1 frame
    7. Spring MVC
      FrameworkServlet.service
      1. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      1 frame
    8. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
      1 frame
    9. Jetty
      ServletHandler$CachedChain.doFilter
      1. org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
      2. org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1448)
      2 frames
    10. Spring
      OncePerRequestFilter.doFilter
      1. org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      2. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      2 frames
    11. Jetty
      ServletHandler$CachedChain.doFilter
      1. org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
      1 frame