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

ProxySelector.connectFailed and .select never throw IllegalArgumentException

XMLWordPrintable

    • beta2
    • sparc
    • solaris_2.6

      Name: akR10050 Date: 10/15/2003


      Javadoc API specification for methods
         ProxySelector.connectFailed(URI, SocketAddress, IOException)
         ProxySelector.select(URI)
      specifies that IllegalArgumentException has to be thrown when either argument of
      these methods is null.

      However, with the default ProxySelector provided with the RI, in case of
      connectFailed(*) no exception is thrown, and select() throws
      NullPointerException.

      The behaviour of the connectFailed method can be verified with the following
      testcase:
      -------------- Test46.java -----------------------------------------------------------
      import java.net.*;
      import java.io.*;

      public class Test46 {
          public static void main(String[] args) {
              PrintStream ref = System.out;
              int errors = 0;
              ProxySelector ps = ProxySelector.getDefault();
              URI[] uris = null;
              try {
                  uris = new URI[] { null, new URI("http://java.sun.com") };
              } catch (URISyntaxException use) {
                  ref.println("Unexpected URISyntaxException");
                  return;
              }
              SocketAddress[] sas = null;
              try {
                  sas = new SocketAddress[] { null,
                      new InetSocketAddress(InetAddress.getLocalHost(), 0)
                  };
              } catch (UnknownHostException uhe) {
                  ref.println("Unexpected UknownHostException");
                  return;
              } catch (IllegalArgumentException iae) {
                  ref.println("Unexpected IllegalArgumentException");
                  return;
              }

              IOException[] ioes = new IOException[] { null,
                  new IOException("test") };

              boolean passed = false;

              for (int i=0; i <uris.length; i++) {
                  for (int j=0; j < sas.length; j++) {
                      for (int k=0; k < ioes.length; k++ ) {
                          try {
                              ps.connectFailed(uris[i], sas[j], ioes[k]);
                              ref.println("No exception thrown");
                          } catch (IllegalArgumentException iae) {
                              passed = true;
                          } catch (NullPointerException npe) {
                              ref.println("NullPointerException thrown");
                          } finally {
                              if ( ( uris[i] == null || sas[j] == null
                                      || ioes[k] == null ) && !passed ) {
                                  ref.println("connectFailed should have thrown"
                                          + " IllegalArgumentException:");
                                  ref.println("uri: " + uris[i]);
                                  ref.println("sa: " + sas[j]);
                                  ref.println("ioe: " + ioes[k]);
                                  errors++;
                              } else if ( uris[i] != null && sas[j]!= null
                                      && ioes[k] != null && passed ) {
                                  ref.println("connectFailed should have not thrown"
                                          + " IllegalArgumentException:");
                                  ref.println("uri: " + uris[i]);
                                  ref.println("sa: " + sas[j]);
                                  ref.println("ioe: " + ioes[k]);
                                  errors++;
                              }
                              passed = false;
                          }
                      }
                  }
              }

              if ( errors> 0 ) {
                  ref.println(errors + " errors during the test");
                  return;
              }
              ref.println("Test passed");
              ref.flush();
              return;
          }
      }
      --------------- End of Test46.java ---------------------------------------------------

      ======================================================================
      ###@###.### 2004-09-20

            jccollet Jean-Christophe Collet (Inactive)
            kaisunw Kai Kai (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: