Clarify when JsonSyntaxException is thrown - #3127
Open
cindykrafft wants to merge 1 commit into
Open
cindykrafft wants to merge 1 commit into
cindykrafft wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The Javadoc said the exception is only raised for malformed JSON, but Gson also throws it for well-formed JSON which does not match the expected type, for example a JSON string where an array was expected, or a number which is out of range for an `int`. It also mentioned writing, but the exception is only thrown when reading. Resolves google#1138 Claude-Session: https://claude.ai/code/session_01X59fWmqnA4Nmb9rggkTP7n
cindykrafft
force-pushed
the
fix-jsonsyntaxexception-javadoc
branch
from
September 23, 2026 21:08
e92e375 to
265c2cb
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Closes #1138
Description
The Javadoc of
JsonSyntaxExceptionsays it is raised when Gson "attempts to read (or write) a malformed JSON element". In practice it is also thrown for well-formed JSON which does not match the expected type, which is how the@throws JsonSyntaxExceptionclauses of theGson.fromJsonmethods already describe it ("if json is not a valid representation for an object of type ..."):This PR only updates the class Javadoc to describe both cases, using these two situations as examples. It also drops "(or write)", since none of the places in the
gsonmodule which throwJsonSyntaxExceptionare on the serialization side. The separateprotomodule has one:LegacyProtoTypeAdapterFactory.java:537throwsJsonSyntaxException("Groups are not supported")fromwriteSingleFieldValue. I'm happy to keep "(or write)" if you'd rather the Javadoc cover that case.No behavior is changed. The question raised in #2816 of whether a different exception type should be thrown is intentionally left out of scope.
Checklist
mvn spotless:checkpasses)If necessary, new public API validates arguments(no new API)New public API has Javadoc(no new API)If necessary, new unit tests have been added(Javadoc-only change)mvn clean verifypasses for thegsonmodule