JsonUtil.parseJson("[]") results in a ClassCastException

Issue #142 closed
Bruce MacDonald created an issue

The result of calling JsonUtil.parseJson("[]") is:

java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.jose4j.json.JsonUtil$DupeKeyDisallowingLinkedHashMap
    at org.jose4j.json.JsonUtil.parseJson(JsonUtil.java:62) ~[jose4j.jar:?]

The JsonUtil class assumes that the parsed JSON will result in a map, but an empty array "[]" results in an ArrayList. This causes a ClassCastException as the Arraylist returned cannot be cast as a LinkedHashMap.

The validity of this bug depends on if you consider [] to be valid JSON, but you may want to handle this exception in any case.

Comments (5)

  1. Brian Campbell

    It is valid JSON but JsonUtil isn’t intended to be a general JSON processor. It’s a utility in support of JOSE/JWT functionality and JOSE/JWT JSON is always an JSON Object at the root. JsonUtil is designed for that.

  2. Log in to comment