Skip to content

Improcess error hanling in getJsonSchema - never squash exceptions #372

Open
@Johnlon

Description

@Johnlon

The "Cannot happen" happens often enough in actual use when the user passes in a bad value for the definition pointer.
For example one without a leading "/".

The code should deal with use input more conveniently by making some up front sanit checks perhaps, or at the very least don't just squash the JSONPointerException that comes from Jackson code as exception squashing is pure evil (if you don't mind me sayting so).

I'm trying to use this in a validator where folk provide a configurator and this kind of error handling means I have to check things up front where this library or it's transitive shoujld be doing it elegantly (nice error messages) instead.

public JsonSchema getJsonSchema(final JsonNode schema, final String ptr)
        throws ProcessingException
    {
        BUNDLE.checkNotNull(schema, "nullSchema");
        CORE_BUNDLE.checkNotNull(ptr, "nullPointer");
        final JsonPointer pointer;
        try {
            pointer = new JsonPointer(ptr);
            return validator.buildJsonSchema(schema, pointer);
        } catch (JsonPointerException ignored) {
            // Cannot happen
        }
        throw new IllegalStateException("How did I get there??");
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions