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

JavaDoc bug in JsonArray and JsonElement classes #1908

Closed
HiFromAjay opened this issue Jun 11, 2021 · 0 comments · Fixed by #2178
Closed

JavaDoc bug in JsonArray and JsonElement classes #1908

HiFromAjay opened this issue Jun 11, 2021 · 0 comments · Fixed by #2178

Comments

@HiFromAjay
Copy link
Contributor

The JavaDoc description of getAsDouble method in JsonArray and JsonElement classes states that the method throws “ClassCastException if the element is of not a JsonPrimitive and is not a valid double value.” However, it actually throws an UnsupportedOperationException if the element is not a JsonPrimitive type such as JsonObject. Whereas, it throws a NumberFormatException if the element is not a valid double value such as string. The behavior is the same for getAsInt and getAsLong methods.

The JavaDoc description of getAsBoolean method in JsonArray and JsonElement classes states that the method throws “ClassCastException if the element is of not a JsonPrimitive and is not a valid boolean value.” However, it actually throws an UnsupportedOperationException if the element is not a JsonPrimitive type such as JsonObject. Whereas, it does not throw any exception (returns false) if the element is not a valid boolean value such as string and double. It is not clear though whether the bug is in the documented behavior or the implemented behavior. The behavior is the same for the getAsString method.

HiFromAjay added a commit to HiFromAjay/gson that referenced this issue Jun 11, 2021
… getAsDouble, getAsInt, getAsJsonArray, getAsJsonObject, getAsLong, and getAsString methods of JsonArray class. These test cases, which we wrote according to the specified behavior of each method, that helped us in identifying the documentation bugs in JsonArray and JsonElement classes, which we submitted issues for (Issue google#1908). Note that we have adapted these test cases based on similar tests from the JSON-java project (https://github.com/stleary/JSON-java).
HiFromAjay added a commit to HiFromAjay/gson that referenced this issue Jun 14, 2021
…ods [use fail(...), use JsonArray methods, remove unused values, formatting, google#1909, google#1908]
HiFromAjay added a commit to HiFromAjay/gson that referenced this issue Aug 5, 2021
@Marcono1234 Marcono1234 added the bug label Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants