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

jcmd can fail converting UTF8 output to strings

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 13
    • 11, 12
    • core-svc
    • b17

      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.

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

              Created:
              Updated:
              Resolved: