Skip to content

fix: default encoding for test cases on windows - #72

Merged
quintesse merged 2 commits into
codejive:mainfrom
nx-eric-jarosch:fix-test-encoding
Sep 23, 2026
Merged

quintesse merged 2 commits into
codejive:mainfrom
nx-eric-jarosch:fix-test-encoding

Conversation

@nx-eric-jarosch

@nx-eric-jarosch nx-eric-jarosch commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

new String(byte[]) uses Charset.defaultCharset() as the encoding. This only works on machines where the default charset is UTF-8, because all of the test.properties files are encoded using UTF-8.

Consequently, 21 tests fail on windows, because here the default charset is windows-1252, while the test.properties files are still encoded using UTF-8, causing a mismatch to be detected by the tests.

The fix is to explicitly use the correct encoding.


Additional references

Source code for `new String(byte[])` and javadoc for `Charset.defaultCharset()`:
    /**
     * Constructs a new {@code String} by decoding the specified array of bytes
     * using the {@link Charset#defaultCharset() default charset}. The length
     * of the new {@code String} is a function of the charset, and hence may not
     * be equal to the length of the byte array.
     *
     * <p> The behavior of this constructor when the given bytes are not valid
     * in the default charset is unspecified.  The {@link
     * java.nio.charset.CharsetDecoder} class should be used when more control
     * over the decoding process is required.
     *
     * <p> The contents of the string are unspecified if the byte array
     * is modified during string construction.
     *
     * @param  bytes
     *         The bytes to be decoded into characters
     *
     * @since  1.1
     */
    public String(byte[] bytes) {
        this(Charset.defaultCharset(), bytes, 0, bytes.length);
    }

    /**
     * Returns the default charset of this Java virtual machine.
     *
     * <p> The default charset is {@code UTF-8}, unless changed in an
     * implementation specific manner.
     *
     * @implNote An implementation may override the default charset with
     * the system property {@code file.encoding} on the command line. If the
     * value is {@code COMPAT}, the default charset is derived from
     * the {@code native.encoding} system property, which typically depends
     * upon the locale and charset of the underlying operating system.
     *
     * @return  A charset object for the default charset
     * @see System##file.encoding file.encoding
     * @see System##native.encoding native.encoding
     *
     * @since 1.5
     */
    public static Charset defaultCharset()

`new String(byte[])` uses `Charset.defaultCharset()` as the encoding.
This only works on machines where the default charset is UTF-8, because all of the test.properties files are encoded using UTF-8.

Consequently, 21 tests fail on windows, because here the default charset is windows-1252, while the test.properties files are still encoded using UTF-8, causing a mismatch to be detected by the tests.

The fix is to explicitly use the correct encoding.
@quintesse
quintesse merged commit 3250921 into codejive:main Sep 23, 2026
1 check passed
@quintesse

Copy link
Copy Markdown
Collaborator

This was only for tests, so really a non-risk merge. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants