Skip to content

testDecodeError function in Helpers.java error message clean up #756

Open

Description

@FarmersWrap

Is your feature request related to a problem? Please describe.
When I test the the project. There is a test in ParserTest.java:68. It has side effect that will print following message to err.

Nov 16, 2023 1:17:20 AM io.socket.parser.IOParser$Decoder decodeString
WARNING: An error occured while retrieving data from JSONTokener
org.json.JSONException: Expected a ':' after a key at character 13
	at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
	at org.json.JSONObject.<init>(JSONObject.java:203)
	at org.json.JSONTokener.nextValue(JSONTokener.java:344)
	at org.json.JSONArray.<init>(JSONArray.java:125)
	at org.json.JSONTokener.nextValue(JSONTokener.java:348)
	at io.socket.parser.IOParser$Decoder.decodeString(IOParser.java:183)
	at io.socket.parser.IOParser$Decoder.add(IOParser.java:92)
	at io.socket.parser.Helpers.testDecodeError(Helpers.java:38)
	at io.socket.parser.ParserTest.decodeInError(ParserTest.java:68)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55)
	at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
	at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:107)
	at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:83)
	at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
	at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:161)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

Describe the solution you'd like
A clear and concise description of what you want to happen.
This is an error thrown by JSONTokener. It is not relevant to this project. And all the behaviors are under control. It is better to avoid the error message.
I think it would be better to change the decodeString function at io.socket.parser.IOParser$Decoder.decodeString(IOParser.java:183) to check the validity of the json string.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Change the testcase

Additional context
Add any other context or screenshots about the feature request here.

Activity

  1. darrachequesne commented on Nov 17, 2023

    @darrachequesne
    Member

    Sounds reasonable! Would you mind opening a PR?

  2. FarmersWrap commented on Nov 17, 2023

    @FarmersWrap
    ContributorAuthor

    No problem! But I realized the decoder highly depends on JSONTokener, you wouldn't want to double-check the json string nor change the logic of logging JSONTokener error message. Then I changed the behavior of the logger in the test case. Please refer to the PR.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions