Skip to content

JavaDoc bug in JsonArray and JsonElement classes #1908

@HiFromAjay

Description

@HiFromAjay

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions