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

Method throws IOException when object should be returned

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta2
    • x86
    • windows_2000



      Name: bsC130419 Date: 06/21/2001


      java version "1.3.1" [vs. 1.4 -- see below]
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      A call to method test throws IOException, but test doesn't declare any
      Exceptions to be thrown.

        static URLConnection test(URL url) {
          URLConnection uc = null;
          try {
            uc = url.openConnection();
            System.out.println("Response code: " + ((HttpURLConnection)
      uc).getResponseCode());
          } catch (Throwable t) {
            System.out.println("Exception intercepted!");
            t.printStackTrace();
          } finally {
            System.out.println("!!!!! finalize");
            try {
              System.out.println("!!!!! 1");
              ((HttpURLConnection)uc).disconnect();
              System.out.println("!!!!! 2");
            } catch (Throwable t3) {}
            System.out.println("!!!!! 3");
          }
          return uc;
        }

        public static void main(String args[]) {
          try {
            String url = "http://javor.pef.uni-lj.si/~ori99/";
            URLConnection uc = test(new URL(url));
            System.out.println("Done: " + ((HttpURLConnection)uc).getResponseCode()
      + ".");
          } catch (Throwable t) {
            System.out.println("Error:");
            t.printStackTrace();
          }
        }

      Output with JDK 1.4:

      Response code: 403
      !!!!! finalize
      !!!!! 1
      !!!!! 2
      !!!!! 3
      Error:
      java.io.IOException: Server returned HTTP response code: 403 for URL: http://jav
      or.pef.uni-lj.si/~ori99/
              at sun.net.www.protocol.http.HttpURLConnection.getInputStream
      (HttpURLConnection.java:558)
              at java.net.HttpURLConnection.getResponseCode
      (HttpURLConnection.java:235)
              at si.noviforum.util.TimeoutURLConnection.test
      (TimeoutURLConnection.java:236)
              at si.noviforum.util.TimeoutURLConnection.main
      (TimeoutURLConnection.java:257)

      Output with JDK 1.3.1 (or older):

      Response code: 403
      !!!!! finalize
      !!!!! 1
      !!!!! 2
      !!!!! 3
      Done: 403.
      (Review ID: 126937)
      ======================================================================

            ywangsunw Yingxian Wang (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: