-
Notifications
You must be signed in to change notification settings - Fork 71
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
Java: Empty MotD fix for JSON #204
Conversation
✅ Build minestat 1.0.0.378 completed (commit 9080fd204e by @ldilley) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ldilley!
Thank you for the PR, though I do think there is a small problem: The JSON protocol doesn't work at all anymore in the Java variant ;)
First of all, when the "description" field is missing from the server response, the line with setMotd(jobj.get("description")
[...]
raises an exception every time, causing the autodetection to fallback to some other protocol.
Secondly, with your change to that same line from .toString()
to .getAsString()
there are two problems:
1.: The "MOTD" field in the MineStat class is the raw representation of the motd, so either a JSON string, or a string with legacy formatting. The .toString
is there explicitly, because it returns the json string for a (maybe nested) Gson object - exactly what we want for the MOTD field.
The double quotes would be perfectly fine and expected, as they form a valid JSON string for "empty string". So both options would be alright: either returning a empty string, or returning doublequotes (JSON representation for empty string).
2.: If the MOTD is not empty, the description
field is (very often) an object/array, not a primitive string. So the getAsString
call fails with an UnuspportedOperationException, since it is only meant to convert a json primitive string to a Java string.
Best regards,
MindSolve
✅ Build minestat 1.0.0.379 completed (commit 474f71cfb8 by @ldilley) |
After some discussion in Discord, @mindsolve proposed the changes committed in 4210586. |
Kudos, SonarCloud Quality Gate passed! |
Proposed Changes
3.0.5
to3.0.6
.