You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
… 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).
The JavaDoc description of
getAsDouble
method inJsonArray
andJsonElement
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 anUnsupportedOperationException
if the element is not aJsonPrimitive
type such asJsonObject
. Whereas, it throws aNumberFormatException
if the element is not a valid double value such as string. The behavior is the same forgetAsInt
andgetAsLong
methods.The JavaDoc description of
getAsBoolean
method inJsonArray
andJsonElement
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 anUnsupportedOperationException
if the element is not aJsonPrimitive
type such asJsonObject
. Whereas, it does not throw any exception (returnsfalse
) 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 thegetAsString
method.The text was updated successfully, but these errors were encountered: