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

HttpsURLConnection: Remove the IOException from the constructor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 5.0
    • security-libs
    • b40
    • sparc
    • solaris_7
    • Verified

      Name: mtR10145 Date: 01/13/2004

      The spec of HttpsURLConnection(URLáurl) states:

      Throws: IOException - if the connection can't be established

      However, this constructor does not throw IOException for null
      argument. Test code below illustrates this bug.
      =================== Test24.java =========================
      import javax.net.ssl.*;
      import java.security.cert.Certificate;
      import java.net.URL;
      import java.io.IOException;

      public class Test24 {

          public static void main(String argv[]) {
              Test24 test = new Test24();
              test.go();
          }

          public void go() {
              try {
                  HttpsURLConnection c = (HttpsURLConnection) new MyHttpsURLConnection((URL) null);
                  System.out.println("Error: expected exception not thrown");
              } catch (IOException ioe) {
                  System.out.println("Passed");
              } catch (NullPointerException npe) {
                  System.out.println("Error: unspecified NPE thrown: " + npe);
              }
          }


      class MyHttpsURLConnection extends HttpsURLConnection {
          public MyHttpsURLConnection(URL url) throws IOException {
              super(url);
          }

          public String getCipherSuite() {
              return new String("");
          }

          public Certificate[] getLocalCertificates() {
              return null;
          }

          public Certificate[] getServerCertificates() {
              return null;
          }

          public boolean usingProxy() {
              return false;
          }

          public void connect() {
          }

          public void disconnect() {
          }
      }
      }
      =================== output (build 1.5.0-beta-b32 =============
      Error: expected exception not thrown
      ======================================================================

            wetmore Bradford Wetmore
            cmssunw Cms Cms (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: