java.lang.NullPointerException

Spring JIRA | chris snow | 6 years ago
  1. 0

    I am trying to call a rest service that has an optional path parameter (areaId, below). Setting the optional path parameter to null causes a NPE (exception below). The implications of this are that I have to create a different version of the method call for each optional call parameter and use lots of conditional logic to check if parameter values are null to decide which method to use. {code} String FIND_AREAS_QUERY = "/areas/{areaId}?countryId={countryId}&cityId={cityId}"; searchCriteria.setCountryID(123); searchCriteria.setCityID(345); searchCriteria.setAreaID(null); areas = restTemplate.getForObject( restEndpointUrl + FIND_AREAS_QUERY, Areas.class, searchCriteria.getAreaID(), /* NPE */ searchCriteria.getCountryID(), searchCriteria.getCityID() ); {code} The exception is as follows: {code} java.lang.NullPointerException at org.springframework.web.util.UriTemplate.expand(UriTemplate.java:128) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:400) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199) {code} The current workaround is below: This can get quite a burden for lots of optional parameters. {code} String FIND_AREAS_QUERY = "/areas/{areaId}?countryId={countryId}&cityId={cityId}"; searchCriteria.setCountryID(123); searchCriteria.setCityID(345); searchCriteria.setAreaID(null); if (searchCriteria.getAreaID() != null) { areas = restTemplate.getForObject( restEndpointUrl + FIND_AREAS_QUERY, Areas.class, searchCriteria.getAreaID(), searchCriteria.getCountryID(), searchCriteria.getCityID() ); } else { areas = restTemplate.getForObject( restEndpointUrl + FIND_AREAS_QUERY, Areas.class, searchCriteria.getCountryID(), searchCriteria.getCityID() ); } {code}

    Spring JIRA | 6 years ago | chris snow
    java.lang.NullPointerException
  2. 0

    I am trying to call a rest service that has an optional path parameter (areaId, below). Setting the optional path parameter to null causes a NPE (exception below). The implications of this are that I have to create a different version of the method call for each optional call parameter and use lots of conditional logic to check if parameter values are null to decide which method to use. {code} String FIND_AREAS_QUERY = "/areas/{areaId}?countryId={countryId}&cityId={cityId}"; searchCriteria.setCountryID(123); searchCriteria.setCityID(345); searchCriteria.setAreaID(null); areas = restTemplate.getForObject( restEndpointUrl + FIND_AREAS_QUERY, Areas.class, searchCriteria.getAreaID(), /* NPE */ searchCriteria.getCountryID(), searchCriteria.getCityID() ); {code} The exception is as follows: {code} java.lang.NullPointerException at org.springframework.web.util.UriTemplate.expand(UriTemplate.java:128) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:400) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199) {code} The current workaround is below: This can get quite a burden for lots of optional parameters. {code} String FIND_AREAS_QUERY = "/areas/{areaId}?countryId={countryId}&cityId={cityId}"; searchCriteria.setCountryID(123); searchCriteria.setCityID(345); searchCriteria.setAreaID(null); if (searchCriteria.getAreaID() != null) { areas = restTemplate.getForObject( restEndpointUrl + FIND_AREAS_QUERY, Areas.class, searchCriteria.getAreaID(), searchCriteria.getCountryID(), searchCriteria.getCityID() ); } else { areas = restTemplate.getForObject( restEndpointUrl + FIND_AREAS_QUERY, Areas.class, searchCriteria.getCountryID(), searchCriteria.getCityID() ); } {code}

    Spring JIRA | 6 years ago | chris snow
    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.web.util.UriTemplate.expand()
    2. Spring
      RestTemplate.getForObject
      1. org.springframework.web.util.UriTemplate.expand(UriTemplate.java:128)
      2. org.springframework.web.client.RestTemplate.execute(RestTemplate.java:400)
      3. org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:199)
      3 frames