-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
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.