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

java.net.Socket(String,int) throws wrong exception

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description

      (Note, the original bug was against SSLSocket, but SSLSocket is basically
      using the Socket superclass, which is primarily the one who determines
      which exceptions to throw. I'm reassigning to them, but if there is
      a SSL-specific issue, please let me know. -Brad)

      Name: ktR10099 Date: 12/18/2003



      According to the spec for javax.net.ssl.SSLSocket.SSLSocket(String host,
      int port) it should throw "...UnknownHostException - if the host is not
      known". Current implementation throws different exceptions being given
      different wron host names and different port values. While
      ConnectException and NoRouteToHostException can be considered as legal
      since both are subclasses of IOExceptions, IllegalArgumentException for
      name with spaces seems to be invalid. Please find source, demonstrating
      the problem, below.

      ---------------------------test144.java---------------------------
      import javax.net.ssl.SSLSession;
      import javax.net.ssl.SSLSocket;
      import javax.net.ssl.HandshakeCompletedListener;
      import java.net.InetAddress;
      import java.io.IOException;

      public class test144 {
          public static void main(String[] args) {
          String[] badHosts = {null,
              "",
              "no_such_host",
              "name with spaces",
              "very.long.name.of.host.that.does.not.actually.exist"};

              System.out.println("Testing for port 0\n");
              for (int i = 0; i < badHosts.length; i++) {
                  try {
                      MySSLSocket ms = new MySSLSocket(badHosts[i], 0);
                      System.out.println("Exception not thrown" +
                          " for name " + badHosts[i]);
                  } catch (Exception e) {
                      System.out.println("\"" + badHosts[i] + "\" " + e);
                  }
              }

              System.out.println("\nTesting for port 8080\n");
              for (int i = 0; i < badHosts.length; i++) {
                  try {
                      MySSLSocket ms = new MySSLSocket(badHosts[i], 8080);
                      System.out.println("Exception not thrown" +
                          " for name " + badHosts[i]);
                  } catch (Exception e) {
                      System.out.println("\"" + badHosts[i] + "\" " + e);
                  }
              }
              System.out.println("Finished");
          }
      }

      class MySSLSocket extends SSLSocket {
          public MySSLSocket() throws IOException {
              super();
          }

          public MySSLSocket(InetAddress address, int port) throws IOException {
              super(address, port);
          }

          public MySSLSocket(InetAddress address, int port, InetAddress clientAddress, int clientPort) throws IOException {
              super(address, port, clientAddress, clientPort);
          }

          public MySSLSocket(String host, int port) throws IOException {
              super(host, port);
          }

          public MySSLSocket(String host, int port, InetAddress clientAddress, int clientPort) throws IOException {
              super(host, port, clientAddress, clientPort);
          }

          public void addHandshakeCompletedListener(HandshakeCompletedListener listener) {}

          public String[] getEnabledCipherSuites() {
              return null;
          }

          public String[] getEnabledProtocols() {
              return null;
          }

          public boolean getEnableSessionCreation() {
              return false;
          }

          public boolean getNeedClientAuth() {
              return false;
          }

          public SSLSession getSession() {
              return null;
          }

          public String[] getSupportedCipherSuites() {
              return null;
          }

          public String[] getSupportedProtocols() {
              return null;
          }

          public boolean getUseClientMode() {
              return false;
          }

          public boolean getWantClientAuth() {
              return false;
          }

          public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {}

          public void setEnabledCipherSuites(String[] suites) {}

          public void setEnabledProtocols(String[] protocols) {}

          public void setEnableSessionCreation(boolean flag) {}

          public void setNeedClientAuth(boolean need) {}

          public void setUseClientMode(boolean mode) {}

          public void setWantClientAuth(boolean want) {}

          public void startHandshake() {}
      }


      -------------------------output of test144--------------------------
      java full version "1.5.0-beta-b31"
      Testing for port 0

      "null" java.net.NoRouteToHostException: Cannot assign requested address
      "" java.net.NoRouteToHostException: Cannot assign requested address
      "no_such_host" java.net.UnknownHostException: no_such_host
      "name with spaces" java.lang.IllegalArgumentException: URI can't be null.
      "very.long.name.of.host.that.does.not.actually.exist" java.net.UnknownHostException: very.long.name.of.host.that.does.not.actually.exist

      Testing for port 8080

      "null" java.net.ConnectException: Connection refused
      "" java.net.ConnectException: Connection refused
      "no_such_host" java.net.UnknownHostException: no_such_host
      "name with spaces" java.lang.IllegalArgumentException: URI can't be null.
      "very.long.name.of.host.that.does.not.actually.exist" java.net.UnknownHostException: very.long.name.of.host.that.does.not.actually.exist
      Finished
      ---------------------------------------------------------------------
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              jccollet Jean-Christophe Collet (Inactive)
              Reporter:
              kvtsunw Kvt Kvt (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: