Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KyleAure opened this issue Oct 13, 2023 · 0 comments · May be fixed by #349
Open

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

KyleAure opened this issue Oct 13, 2023 · 0 comments · May be fixed by #349

Comments

@KyleAure
Copy link

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�ㅢ���

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 a pull request may close this issue.

1 participant