java.lang.NullPointerException

Spring JIRA | Lasse Westh-Nielsen | 5 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    From Craig Giordano: {code} I am using SDN 2.1.0.BUILD-SNAPSHOT and Neo4j 1.7. I have modeled an Activity that has an activityCode and a time range containing a begin and end date. I need to find the Activity with the latest begin date. At first I thought, just write a cypher query returning the Activity and begin date as a @MapResult sorting by begin date DESC and grab the first one from the list. This works fine. When there are no Activity's I get an empty list back as expected. Then I thought, a list is silly when I am only interested in the first item so I decided to try the LIMIT key word, ending my query with LIMIT 1. I changed the signature of my method to return a @MapResult instead of a List and it worked. Except for the case where there are no satisfying Activity's. Instead of returning null, I get a NullPointException as follows: java.lang.NullPointerException at org.springframework.data.neo4j.support.conversion.EntityResultConverter.extractMapResult(EntityResultConverter.java:85) at org.springframework.data.neo4j.support.conversion.EntityResultConverter.convert(EntityResultConverter.java:97) at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.convert(QueryResultBuilder.java:102) at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.singleOrNull(QueryResultBuilder.java:95) at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:96) at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:70) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:313) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy35.findWithLatestBeginByActivityCodeAndTimeRange(Unknown Source) at com.ierin.paragon2.domain.repository.ActivityRepositoryTest.canFindActivityByActivityCodeAndTimeRange_BadActivityCode(ActivityRepositoryTest.java:65) To show some specifics here are two methods with the same cypher query but different behavior when the results are zero: @Query("start activity=node:DATA_SET_ID_INDEX(dataSetId = {scheduleDataSetId}) " + "match activity-[:MODEL_SCHEDULE_ACTIVITY]->plantVariable, activity-[:timeRange]->t " + "where plantVariable.dataSetId = {modelDataSetId} " + "and activity.activityCode = {activityCode} " + "and t.begin < {end} " + "and (t.end? is null or t.end > {begin}) " + "return activity, t.begin as beginDate order by beginDate desc limit 1") ActivityBeginDateResult findWithLatestBeginByActivityCodeAndTimeRange(@Param("modelDataSetId") String modelDataSetId, @Param("scheduleDataSetId") String scheduleDataSetId, @Param("activityCode") String activityCode, @Param("begin") Long begin, @Param("end") Long end); @Query("start activity=node:DATA_SET_ID_INDEX(dataSetId = {scheduleDataSetId}) " + "match activity-[:MODEL_SCHEDULE_ACTIVITY]->plantVariable, activity-[:timeRange]->t " + "where plantVariable.dataSetId = {modelDataSetId} " + "and activity.activityCode = {activityCode} " + "and t.begin < {end} " + "and (t.end? is null or t.end > {begin}) " + "return activity, t.begin as beginDate order by beginDate desc limit 1") List<ActivityBeginDateResult> findWithLatestBeginByActivityCodeAndTimeRangeInList(@Param("modelDataSetId") String modelDataSetId, @Param("scheduleDataSetId") String scheduleDataSetId, @Param("activityCode") String activityCode, @Param("begin") Long begin, @Param("end") Long end); The first method throws the NullPointerException while the second returns an empty List. Is this a bug or am I misusing the API? Thanks, Craig {code}

    Spring JIRA | 5 years ago | Lasse Westh-Nielsen
    java.lang.NullPointerException
  2. 0

    From Craig Giordano: {code} I am using SDN 2.1.0.BUILD-SNAPSHOT and Neo4j 1.7. I have modeled an Activity that has an activityCode and a time range containing a begin and end date. I need to find the Activity with the latest begin date. At first I thought, just write a cypher query returning the Activity and begin date as a @MapResult sorting by begin date DESC and grab the first one from the list. This works fine. When there are no Activity's I get an empty list back as expected. Then I thought, a list is silly when I am only interested in the first item so I decided to try the LIMIT key word, ending my query with LIMIT 1. I changed the signature of my method to return a @MapResult instead of a List and it worked. Except for the case where there are no satisfying Activity's. Instead of returning null, I get a NullPointException as follows: java.lang.NullPointerException at org.springframework.data.neo4j.support.conversion.EntityResultConverter.extractMapResult(EntityResultConverter.java:85) at org.springframework.data.neo4j.support.conversion.EntityResultConverter.convert(EntityResultConverter.java:97) at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.convert(QueryResultBuilder.java:102) at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.singleOrNull(QueryResultBuilder.java:95) at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:96) at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:70) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:313) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy35.findWithLatestBeginByActivityCodeAndTimeRange(Unknown Source) at com.ierin.paragon2.domain.repository.ActivityRepositoryTest.canFindActivityByActivityCodeAndTimeRange_BadActivityCode(ActivityRepositoryTest.java:65) To show some specifics here are two methods with the same cypher query but different behavior when the results are zero: @Query("start activity=node:DATA_SET_ID_INDEX(dataSetId = {scheduleDataSetId}) " + "match activity-[:MODEL_SCHEDULE_ACTIVITY]->plantVariable, activity-[:timeRange]->t " + "where plantVariable.dataSetId = {modelDataSetId} " + "and activity.activityCode = {activityCode} " + "and t.begin < {end} " + "and (t.end? is null or t.end > {begin}) " + "return activity, t.begin as beginDate order by beginDate desc limit 1") ActivityBeginDateResult findWithLatestBeginByActivityCodeAndTimeRange(@Param("modelDataSetId") String modelDataSetId, @Param("scheduleDataSetId") String scheduleDataSetId, @Param("activityCode") String activityCode, @Param("begin") Long begin, @Param("end") Long end); @Query("start activity=node:DATA_SET_ID_INDEX(dataSetId = {scheduleDataSetId}) " + "match activity-[:MODEL_SCHEDULE_ACTIVITY]->plantVariable, activity-[:timeRange]->t " + "where plantVariable.dataSetId = {modelDataSetId} " + "and activity.activityCode = {activityCode} " + "and t.begin < {end} " + "and (t.end? is null or t.end > {begin}) " + "return activity, t.begin as beginDate order by beginDate desc limit 1") List<ActivityBeginDateResult> findWithLatestBeginByActivityCodeAndTimeRangeInList(@Param("modelDataSetId") String modelDataSetId, @Param("scheduleDataSetId") String scheduleDataSetId, @Param("activityCode") String activityCode, @Param("begin") Long begin, @Param("end") Long end); The first method throws the NullPointerException while the second returns an empty List. Is this a bug or am I misusing the API? Thanks, Craig {code}

    Spring JIRA | 5 years ago | Lasse Westh-Nielsen
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.springframework.data.neo4j.support.conversion.EntityResultConverter.extractMapResult()
    2. Spring Data Neo4j
      GraphRepositoryQuery.execute
      1. org.springframework.data.neo4j.support.conversion.EntityResultConverter.extractMapResult(EntityResultConverter.java:85)
      2. org.springframework.data.neo4j.support.conversion.EntityResultConverter.convert(EntityResultConverter.java:97)
      3. org.springframework.data.neo4j.conversion.QueryResultBuilder$1.convert(QueryResultBuilder.java:102)
      4. org.springframework.data.neo4j.conversion.QueryResultBuilder$1.singleOrNull(QueryResultBuilder.java:95)
      5. org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:96)
      6. org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:70)
      6 frames
    3. Spring Data Core
      RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke
      1. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:313)
      1 frame
    4. Spring AOP
      ReflectiveMethodInvocation.proceed
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      1 frame
    5. Spring Tx
      TransactionInterceptor.invoke
      1. org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      1 frame
    6. Spring AOP
      ReflectiveMethodInvocation.proceed
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      1 frame
    7. Spring Tx
      PersistenceExceptionTranslationInterceptor.invoke
      1. org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
      1 frame
    8. Spring AOP
      JdkDynamicAopProxy.invoke
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      2. org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      2 frames
    9. Unknown
      $Proxy35.findWithLatestBeginByActivityCodeAndTimeRange
      1. $Proxy35.findWithLatestBeginByActivityCodeAndTimeRange(Unknown Source)
      1 frame
    10. com.ierin.paragon2
      ActivityRepositoryTest.canFindActivityByActivityCodeAndTimeRange_BadActivityCode
      1. com.ierin.paragon2.domain.repository.ActivityRepositoryTest.canFindActivityByActivityCodeAndTimeRange_BadActivityCode(ActivityRepositoryTest.java:65)
      1 frame