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

Misleading code in JSSE SSLEngine guide

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 5.0
    • 8
    • docs
    • x86
    • windows_2000

    Description

      A DESCRIPTION OF THE PROBLEM :
      The code example contains blocks to handle -1 return values from SocketChannel.write() and SocketChannel.read(), and comments stating that these blocks handle the case where the SocketChannel is closed.

      This is correct in the case of SocketChannel.read(), but SocketChannel.write() never returns -1,and throws a SocketException if the channel is closed.

      The test for -1 after the write(), and the associated empty code block and comment should be deleted.

      NOTE: this incorrect code sequence occurs not once but twice.

      Note also that in the second occurrence, myNetData.hasRemaining() is incorrectly written as myNetData().hasRemaining().

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
              while(myNetData.hasRemaining()) {
                  int num = socketChannel.write(myNetData);
      if (num == 0) {
      // no bytes written; try again later
      }



      ACTUAL -
              while(myNetData.hasRemaining()) {
                  int num = socketChannel.write(myNetData);
      if (num == -1) {
      // handle closed channel
      } else if (num == 0) {
      // no bytes written; try again later
      }


      URL OF FAULTY DOCUMENTATION :
      file:///%JAVA_HOME%/docs/guide/security/jsse/JSSERefGuide.html#SSLENG

      Attachments

        Activity

          People

            sharonz Sharon Zakhour (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: