Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024810

java.net.HttpURLConnection.getResponseCode return IOException instead of code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 8
    • core-libs
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b100)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b42, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux walec51-linux 3.8.0-29-generic #42-Ubuntu SMP Tue Aug 13 19:40:39 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Found it while developing an app that uses the Hessian protocol. java.net.HttpURLConnection.getResponseCode throws IOException instead of returning HTTP codes 4xx and 5xxx

      This makes exception handling useless. If the client app user type the wrong username/password I can only give him a Fatal connection error message because there is no way to get the response code.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to java.net.HttpURLConnection.getResponseCode from an URL that returns a 4xx or 5xx code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The HTTP code.
      ACTUAL -
      IOException.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Same thing happens on error codes 401 or 403 for example:

      Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8001/ProdokoSecurityService
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1781)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1382)
      at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
      at com.caucho.hessian.client.HessianURLConnection.sendRequest(HessianURLConnection.java:112)
      ... 17 more

      REPRODUCIBILITY :
      This bug can be reproduced often.

            chegar Chris Hegarty
            igerasim Ivan Gerasimov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: