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

HttpsURLConnection.getCipherSuite throws NullPointerException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0.3
    • CPU:
      x86
    • OS:
      linux

      Backports

        Description

        I get a java.lang.NullPointerException if I call the getCipherSuite() method
        of HttpsURLConnection before calling the connect() method.
        It works fine if I call it after the connect() method.

        Here is the code I used with a custom HTTPS server and a KeyStore that I
        generated with keytool.
        Running it with: java Bug 1, causes a java.lang.NullPointerException
        Running it with: java Bug 2, works fine.

        import java.io.*;
        import java.net.*;
        import java.security.*;
        import com.sun.net.ssl.HttpsURLConnection;

        public class Bug {
          public static void main(String[] args) throws Exception {
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
            System.setProperty("javax.net.ssl.trustStore", "keystore");
            System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
            URL url = new URL("https", "localhost", 2001, "file");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            if (args.length == 1 && args[0].equals("1")) {
              System.out.println("Cipher Suite = " + connection.getCipherSuite());
            }
            connection.connect();
            if (args.length == 1 && args[0].equals("2")) {
              System.out.println("Cipher Suite = " + connection.getCipherSuite());
            }
          }
        }



          Attachments

            Issue Links

              Activity

                People

                Assignee:
                wetmore Bradford Wetmore
                Reporter:
                duke J. Duke (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: