Spring for Android
  1. Spring for Android
  2. ANDROID-102

SimpleClientHttpResponse throws null pointer exception

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 1.0.0.RELEASE
    • Fix Version/s: 1.0.1.RELEASE
    • Component/s: rest-template
    • Labels:
      None
    • Environment:
      Wndows, using Android emulator

      Description

      During processing a response from the server the SimpleClientHttpResponse throws NullPointerException:
      08-31 19:25:12.906: E/AndroidRuntime(2437): Caused by: java.lang.NullPointerException
      08-31 19:25:12.906: E/AndroidRuntime(2437): at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:62)
      08-31 19:25:12.906: E/AndroidRuntime(2437): at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:46)
      08-31 19:25:12.906: E/AndroidRuntime(2437): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:476)
      08-31 19:25:12.906: E/AndroidRuntime(2437): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:438)
      08-31 19:25:12.906: E/AndroidRuntime(2437): at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:414)

      A reason seems to be that IOException thrown returns null from call to getLocalizedMessage():
      if (ex.getLocalizedMessage().equals(AUTHENTICATION_ERROR))

      { return HttpStatus.UNAUTHORIZED; }

      else

      { throw ex; }

      BTW, what will getLocalizedMessage() return if locale is not English?

        Activity

        Hide
        Sebastian Roth added a comment -

        Added a basic fix in https://github.com/ened/spring-android - you can build the package using that repository and replace the jar in your Android App.

        Show
        Sebastian Roth added a comment - Added a basic fix in https://github.com/ened/spring-android - you can build the package using that repository and replace the jar in your Android App.
        Show
        Mathias Lin added a comment - Related: http://stackoverflow.com/questions/13182519/spring-rest-template-usage-causes-eofexception
        Hide
        Roy Clarkson added a comment - - edited

        The problem is that Google changed the IOException message in Android 4.1 Jelly Bean. Prior to 4.1 it was:

        "Received authentication challenge is null"

        Now in 4.1 the same exception is responding with:

        "No authentication challenges found"

        I'm doing further testing, and will follow up. I should be pushing this change to a build snapshot today, then we'll have a release ASAP to resolve this.

        Show
        Roy Clarkson added a comment - - edited The problem is that Google changed the IOException message in Android 4.1 Jelly Bean. Prior to 4.1 it was: "Received authentication challenge is null" Now in 4.1 the same exception is responding with: "No authentication challenges found" I'm doing further testing, and will follow up. I should be pushing this change to a build snapshot today, then we'll have a release ASAP to resolve this.
        Hide
        Roy Clarkson added a comment -

        Additionally, Android throws an IOException for a 407 in certain cases, with the following exception message:

        "Received HTTP_PROXY_AUTH (407) code while not using proxy"

        Show
        Roy Clarkson added a comment - Additionally, Android throws an IOException for a 407 in certain cases, with the following exception message: "Received HTTP_PROXY_AUTH (407) code while not using proxy"
        Hide
        Roy Clarkson added a comment -

        Improved handling of situations where Android throws IOExceptions related to HTTP Status Codes 401 and 407.

        Show
        Roy Clarkson added a comment - Improved handling of situations where Android throws IOExceptions related to HTTP Status Codes 401 and 407.

          People

          • Assignee:
            Roy Clarkson
            Reporter:
            Leonid Vladimirov
          • Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: