LucasEby opened a new issue, #24967: URL: https://github.com/apache/pulsar/issues/24967
### Search before reporting - [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar. ### Read release policy - [x] I understand that [unsupported versions](https://pulsar.apache.org/contribute/release-policy/#supported-versions) don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker. ### User environment Broker version: 4.2.0-SNAPSHOT Broker Operating system and hardware type: Linux x86_64 GNU/Linux Broker Java version: 17.0.16 ### Issue Description Each of the below tests incorrectly assumes that the json key-value pairs being asserted would have a deterministic order. The order of key-value pairs is not guaranteed in [JSON](https://www.json.org/json-en.html), however. As a result, the ordering can change due to different environments producing the contents in different orders despite the logical contents being the same. Harmless re-ordering could flip the tests from pass to fail despite the data being semantically the same: - org.apache.pulsar.client.impl.schema.SchemaInfoTest$SchemaInfoBuilderTest.testNullPropertyValue - org.apache.pulsar.client.impl.schema.SchemaInfoTest.testSchemaInfoToString I discovered the problem with the [NonDex](https://github.com/TestingResearchIllinois/NonDex) tool. NonDex systematically detects incorrect tests that rely on non-deterministic behaviors in Java APIs—like assuming order of name/value pairs in json files — by exploring all specification-allowed outcomes. It does this by instrumenting undetermined APIs and randomizing the returned order/behavior within what the spec allows. Failures it exposes reliably indicate flawed assumptions in order that were never promised and should be fixed. ### Error messages ```text [INFO] Running org.apache.pulsar.client.impl.schema.SchemaInfoTest [ERROR] Tests run: 9, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 4.137 s <<< FAILURE! -- in org.apache.pulsar.client.impl.schema.SchemaInfoTest [ERROR] org.apache.pulsar.client.impl.schema.SchemaInfoTest$SchemaInfoBuilderTest.testNullPropertyValue -- Time elapsed: 0.002 s <<< FAILURE! java.lang.AssertionError: expected [{ "name": "INT32", "schema": "", "type": "INT32", "timestamp": 0, "properties": {} }] but found [{ "schema": "", "timestamp": 0, "properties": {}, "type": "INT32", "name": "INT32" }] at org.testng.Assert.fail(Assert.java:110) at org.testng.Assert.failNotEquals(Assert.java:1577) at org.testng.Assert.assertEqualsImpl(Assert.java:149) at org.testng.Assert.assertEquals(Assert.java:131) at org.testng.Assert.assertEquals(Assert.java:655) at org.testng.Assert.assertEquals(Assert.java:665) at org.apache.pulsar.client.impl.schema.SchemaInfoTest$SchemaInfoBuilderTest.testNullPropertyValue(SchemaInfoTest.java:342) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:569) at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139) at org.testng.internal.invokers.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:47) at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:76) at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:11) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840) [INFO] [INFO] Results: [INFO] [ERROR] Failures: [ERROR] org.apache.pulsar.client.impl.schema.SchemaInfoTest$SchemaInfoBuilderTest.testNullPropertyValue [INFO] Run 1: PASS [ERROR] Run 2: SchemaInfoTest$SchemaInfoBuilderTest.testNullPropertyValue:342 expected [{ "name": "INT32", "schema": "", "type": "INT32", "timestamp": 0, "properties": {} }] but found [{ "schema": "", "timestamp": 0, "properties": {}, "type": "INT32", "name": "INT32" }] [INFO] [INFO] [ERROR] Tests run: 8, Failures: 1, Errors: 0, Skipped: 2 [INFO] Running org.apache.pulsar.client.impl.schema.SchemaInfoTest [ERROR] Tests run: 6, Failures: 1, Errors: 0, Skipped: 5, Time elapsed: 6.632 s <<< FAILURE! -- in org.apache.pulsar.client.impl.schema.SchemaInfoTest [ERROR] org.apache.pulsar.client.impl.schema.SchemaInfoTest.testSchemaInfoToString[{ "type": "STRING", "schema": "", "properties": {}, "timestamp": 0, "name": "String" }, { "name": "String", "schema": "", "type": "STRING", "timestamp": 0, "properties": {} }](4) -- Time elapsed: 0.013 s <<< FAILURE! java.lang.AssertionError: expected [{ "name": "String", "schema": "", "type": "STRING", "timestamp": 0, "properties": {} }] but found [{ "schema": "", "type": "STRING", "name": "String", "properties": {}, "timestamp": 0 }] at org.testng.Assert.fail(Assert.java:110) at org.testng.Assert.failNotEquals(Assert.java:1577) at org.testng.Assert.assertEqualsImpl(Assert.java:149) at org.testng.Assert.assertEquals(Assert.java:131) at org.testng.Assert.assertEquals(Assert.java:655) at org.testng.Assert.assertEquals(Assert.java:665) at org.apache.pulsar.client.impl.schema.SchemaInfoTest.testSchemaInfoToString(SchemaInfoTest.java:293) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:569) at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139) at org.testng.internal.invokers.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:47) at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:76) at org.testng.internal.invokers.InvokeMethodRunnable.call(InvokeMethodRunnable.java:11) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840) [INFO] [INFO] Results: [INFO] [ERROR] Failures: [ERROR] SchemaInfoTest.testSchemaInfoToString:293 expected [{ "name": "String", "schema": "", "type": "STRING", "timestamp": 0, "properties": {} }] but found [{ "schema": "", "type": "STRING", "name": "String", "properties": {}, "timestamp": 0 }] [INFO] [ERROR] Tests run: 6, Failures: 1, Errors: 0, Skipped: 5 ``` ### Reproducing the issue You can replicate the problem with the [NonDex](https://github.com/TestingResearchIllinois/NonDex) tool commands: ``` mvn -pl pulsar-client -Dtest=org.apache.pulsar.client.impl.schema.SchemaInfoTest#testSchemaInfoToString -DnondexRuns=1 -DreuseForks=false edu.illinois:nondex-maven-plugin:2.2.1:nondex -Dcheckstyle.skip=true -DnondexRunsWithoutShuffling=0 -DnondexSeed=1844946 ``` ``` mvn -pl pulsar-client -Dtest=org.apache.pulsar.client.impl.schema.SchemaInfoTest -DnondexRuns=10 -DreuseForks=false edu.illinois:nondex-maven-plugin:2.2.1:nondex -Dcheckstyle.skip=true -DnondexRunsWithoutShuffling=0 ``` ### Additional information _No response_ ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
