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

Code snippet in javax.naming.ldap package summary does not compile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • core-libs
    • None

      The following code in the "Controls" section does not compile
      ```
      // Perform update
      Context ctx = ectx.createSubsubcontext("cn=newobj");

      // Get response controls
      Control[] respCtls = ectx.getResponseControls();
      if (respCtls != null) {
          // Find the one we want
          for (int i = 0; i < respCtls; i++) {
              if(respCtls[i] instanceof ChangeIDControl) {
                  ChangeIDControl cctl = (ChangeIDControl)respCtls[i];
                  System.out.println(cctl.getChangeID());
              }
          }
      }```

      It will give an error message similar to "Operator '<' cannot be applied to 'int', 'javax.naming.ldap.Control[]'".
      This (^) isn't a direct copy from the javac error but rather an assumption based on my understanding.

      We should change `for (int i = 0; i < respCtls; i++) {` to `for (int i = 0; i < respCtls.length; i++) {`

            nbenalla Nizar Benalla
            nbenalla Nizar Benalla
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: