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

IllegalStateException("Already connected") is thrown when connecting using SSL/TLS fails e.g. due to invalid certificate path

XMLWordPrintable

    • x86
    • os_x

      FULL PRODUCT VERSION :
      java version "1.8.0_74"
      Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      10.11.5 (15F34)

      A DESCRIPTION OF THE PROBLEM :
      An IllegalStateException with wrong message is raised when accessing a site protected by a SSL certificate which cannot be validated using the current truststore.

      The message states that the sun.net.www.protocol.http.HttpUrlConnection is already connected. This is clearly wrong as the connection failed due to invalid certificate path.

      The problem is detected in the setRequestProperty method.

          public synchronized void setRequestProperty(String var1, String var2) {
              if(!this.connected && !this.connecting) {
                  if(var1 == null) {
                      throw new NullPointerException("key is null");
                  } else {
                      if(this.isExternalMessageHeaderAllowed(var1, var2)) {
                          this.requests.set(var1, var2);
                          if(!var1.equalsIgnoreCase("Content-Type")) {
                              this.userHeaders.set(var1, var2);
                          }
                      }

                  }
              } else {
                  throw new IllegalStateException("Already connected");
              }
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Write a Java program which access a URI using HTTPS and protected using a SSL certificate not in the (default) truststore.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The original exception detailing the invalid certificate path should propagate to top-level.
      ACTUAL -
      An IllegalStateException with message "Already Connected", which is clearly wrong as the connection failed due to invalid certificate path.

      REPRODUCIBILITY :
      This bug can be reproduced always.

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: