Skip to content

[TCK] Tests incorrectly assumes that Charset.defaultCharset() is always UTF-8 #348

@KyleAure

Description

@KyleAure

When running the TCK on an OS/JDK combination that uses a different character encoding other than UTF-8 the following tests fail:

<testcase classname="ee.jakarta.tck.json.bind.api.jsonb.JsonbTest" name="testFromJsonReaderClass" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.api.jsonb.JsonbTest" name="testToJsonObjectTypeWriter" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.api.jsonb.JsonbTest" name="testFromJsonReaderType" time="0">
<testcase classname="ee.jakarta.tck.json.bind.api.jsonb.JsonbTest" name="testToJsonObjectWriter" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.customizedmapping.binarydata.BinaryDataCustomizationTest" name="testBase64UrlBinaryDataEncoding" time="0.016">
<testcase classname="ee.jakarta.tck.json.bind.customizedmapping.binarydata.BinaryDataCustomizationTest" name="testByteBinaryDataEncoding" time="0.002">
<testcase classname="ee.jakarta.tck.json.bind.customizedmapping.binarydata.BinaryDataCustomizationTest" name="testBase64BinaryDataEncoding" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.customizedmapping.ijson.IJsonSupportTest" name="testStrictNonObjectOrArrayTopLevel" time="0.002">
<testcase classname="ee.jakarta.tck.json.bind.customizedmapping.ijson.IJsonSupportTest" name="testStrictBinaryDataEncoding" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.basictypes.BasicJavaTypesMappingTest" name="testNumberMapping" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.specifictypes.SpecificTypesMappingTest" name="testEmptyOptionalDoubleMapping" time="0.002">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.specifictypes.SpecificTypesMappingTest" name="testEmptyOptionalMapping" time="0.002">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.specifictypes.SpecificTypesMappingTest" name="testEmptyOptionalArrayMapping" time="0.002">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.specifictypes.SpecificTypesMappingTest" name="testEmptyOptionalLongMapping" time="0.002">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.specifictypes.SpecificTypesMappingTest" name="testEmptyOptionalIntMapping" time="0.001">
<testcase classname="ee.jakarta.tck.json.bind.defaultmapping.specifictypes.SpecificTypesMappingTest" name="testOptionalObjectMapping" time="0.002">

Due to assertions that assume that Charset.defaultCharset() will return UTF-8.
For example (testToJsonObjectTypeWriter) fails with the following when run on z/OS with a default character encoding of IBM-1047:

Failed to marshal using Jsonb.toJson method with Object, Type and Writer arguments.
Expected: a string matching the pattern '\{\s*"instance"\s*:\s*"Test"\s*}'
but: was "�����������z�ㅢ���"
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
at ee.jakarta.tck.json.bind.api.jsonb.JsonbTest.testToJsonObjectTypeWriter(JsonbTest.java:221) 

If we look at this test:
https://github.com/jakartaee/jsonb-api/blob/master/tck/src/main/java/ee/jakarta/tck/json/bind/api/jsonb/JsonbTest.java#L215-L224

new OutputStreamWriter(stream) will return a Writer with a character encoding of IBM-1047.
Then we try to create a string where the bytes are encoded using IBM-1047 but we decode it using UTF-8 resulting in:
�����������z�ㅢ���

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions