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

jcmd can fail converting UTF8 output to strings

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 11, 12
    • Fix Version/s: 13
    • Component/s: core-svc
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b17

      Description

      In the jcmd execute() method, the bytes received from the VM are read into a 256 byte array and then converted to a String via:
        String s = new String(b, 0, n, "UTF-8");
      Since UTF-8 can have characters spanning multiple bytes, the last character might not be fully in the byte array, so it will not be printed. In addition we start with an invalid character in the next iteration of the loop.

      It is better to use a InputStreamReader, which handles all the intricacies of this scenario.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rschmelter Ralf Schmelter
                Reporter:
                rschmelter Ralf Schmelter
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: