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

jdk/test/jdk/java/util/prefs/ExportNode.java relies on default platform encoding

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 17
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b17

      Description

      https://github.com/openjdk/jdk/blob/master/test/jdk/java/util/prefs/ExportNode.java#L50

      [from linked bug report]
      This testcase creates a simple tree of two nodes N1 and N2, where N2 is the
      descendant of N1, and adds a key-value pair each on both. N2 is then exported
      to a ByteArrayOutputStream using the exportNode() method.

      Now, the contract of the exportNode() method makes it clear that it "Emits on
      the specified output stream an XML document.... The UTF-8 character encoding
      will be used."

      So, the ByteArrayOutputStream is going to hold the UTF-8 bytes of the XML
      representation of the given node. We subsequently call toString() on it and
      make some elementary searches. Here, ByteArrayOutputStream.toString() is
      going to use the platforms default charset to wrap the bytes into a String.

      On non-ASCII platforms, like z/OS, we'd end up building a String with a
      non-UTF8 charset and UTF-8 bytes. This mismatch causes failure.

      Proposed fix:
      To make the test resilient to non-ASCII platforms as well, we'd suggest that
      ByteArrayOutputStream be called with the charset name of "UTF-8" as in
      exportStream.toString("UTF-8").

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              dbessono Dmitry Bessonov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: