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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Brian Burkhalter-3
This test emits to a `java.io.ByteArrayOutputStream` the contents of a `java.utils.prefs.Preferences` node. The `UTF-8` character encoding is used [1]. The `ByteArrayOutputStream` is then converted to a `String` using `toString()` which uses the platform's default character set [2]. The resulting `String` is then checked for the node names that it should and should not contain.

This change proposes to use `ByteArrayOutputStream.toString(String)` to obtain the string [3] to maintain consistency of the encoding. It also adds throwing a `RuntimeException` if the node string is not as expected. It is unclear why this test was not already throwing such an exception.

[1] https://docs.oracle.com/en/java/javase/16/docs/api/java.prefs/java/util/prefs/Preferences.html#exportNode(java.io.OutputStream)
[2] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/io/ByteArrayOutputStream.html#toString()
[3] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/io/ByteArrayOutputStream.html#toString(java.lang.String)

-------------

Commit messages:
 - 8264512: jdk/test/jdk/java/util/prefs/ExportNode.java relies on default platform encoding

Changes: https://git.openjdk.java.net/jdk/pull/3332/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3332&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8264512
  Stats: 39 lines in 1 file changed: 21 ins; 0 del; 18 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3332.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3332/head:pull/3332

PR: https://git.openjdk.java.net/jdk/pull/3332
Reply | Threaded
Open this post in threaded view
|

Re: RFR: 8264512: jdk/test/jdk/java/util/prefs/ExportNode.java relies on default platform encoding

Naoto Sato-2
On Fri, 2 Apr 2021 21:45:58 GMT, Brian Burkhalter <[hidden email]> wrote:

> This test emits to a `java.io.ByteArrayOutputStream` the contents of a `java.utils.prefs.Preferences` node. The `UTF-8` character encoding is used [1]. The `ByteArrayOutputStream` is then converted to a `String` using `toString()` which uses the platform's default character set [2]. The resulting `String` is then checked for the node names that it should and should not contain.
>
> This change proposes to use `ByteArrayOutputStream.toString(String)` to obtain the string [3] to maintain consistency of the encoding. It also adds throwing a `RuntimeException` if the node string is not as expected. It is unclear why this test was not already throwing such an exception.
>
> [1] https://docs.oracle.com/en/java/javase/16/docs/api/java.prefs/java/util/prefs/Preferences.html#exportNode(java.io.OutputStream)
> [2] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/io/ByteArrayOutputStream.html#toString()
> [3] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/io/ByteArrayOutputStream.html#toString(java.lang.String)

Looks good.

-------------

Marked as reviewed by naoto (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/3332
Reply | Threaded
Open this post in threaded view
|

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

Brian Burkhalter-3
In reply to this post by Brian Burkhalter-3
On Fri, 2 Apr 2021 21:45:58 GMT, Brian Burkhalter <[hidden email]> wrote:

> This test emits to a `java.io.ByteArrayOutputStream` the contents of a `java.utils.prefs.Preferences` node. The `UTF-8` character encoding is used [1]. The `ByteArrayOutputStream` is then converted to a `String` using `toString()` which uses the platform's default character set [2]. The resulting `String` is then checked for the node names that it should and should not contain.
>
> This change proposes to use `ByteArrayOutputStream.toString(String)` to obtain the string [3] to maintain consistency of the encoding. It also adds throwing a `RuntimeException` if the node string is not as expected. It is unclear why this test was not already throwing such an exception.
>
> [1] https://docs.oracle.com/en/java/javase/16/docs/api/java.prefs/java/util/prefs/Preferences.html#exportNode(java.io.OutputStream)
> [2] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/io/ByteArrayOutputStream.html#toString()
> [3] https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/io/ByteArrayOutputStream.html#toString(java.lang.String)

This pull request has now been integrated.

Changeset: 104e925d
Author:    Brian Burkhalter <[hidden email]>
URL:       https://git.openjdk.java.net/jdk/commit/104e925d
Stats:     39 lines in 1 file changed: 21 ins; 0 del; 18 mod

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

Reviewed-by: naoto

-------------

PR: https://git.openjdk.java.net/jdk/pull/3332