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

HttpURLConnection generates erroneous FileNotFoundException if respCode >=400

XMLWordPrintable

    • sparc
    • solaris_8

      The method getResponseCode() in HttpURLConnection calls
      it's getInputStream() method, which extracts the response code
      from the HTTP response. According to the API doc, and common
      sense, it should return the response code specified by the server
      in the HTTP response. But when the response code specified is
      >=400, it does not return the code, instead it throws a FileNotFoundException.
      This is totally misleading, because the URL was indeed found, and generated
      a valid error response, which is thrown away by HttpURLConnection, so the
      client can never see it, or handle it. This behavior is completely
      inappropriate.

      It is true that HttpURLConnection does not generate the FileNotFoundException
      if the URL in question ends in ".htm", "/", or ".txt", but the point is,
      that it should NEVER throw a FileNotFoundException if it gets a response
      from the server for the given URL, no matter what the URL is or what the
      response is.

            alanb Alan Bateman
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: