Skip to content

Replace NoSuchElementException with SerializationException on ConfigurationNode#require #624

Description

@mega12345mega

Right now ConfigurationNode#require throws NoSuchElementException, which is a RuntimeException and thus easily missed:

throw new NoSuchElementException("Node value was null when a non-null node was require()d");

This is distinct from all of the #get methods, which throw SerializationException (a configurate-specific checked exception) on failure. This also means that the exception is missing the additional details that are usually provided (path, expected type). As a result, I have to use this pattern:

ConfigurationNode threadsNode = node.node("threads");
Integer threads = threadsNode.get(Integer.class);
if (threads == null)
    throw new SerializationException(threadsNode, Integer.class, "expected value but found null");

When node.node("threads").require(Integer.class) would be much more succinct if it threw the correct exception.

If this behavior is intended (or backwards compatibility is a concern), I still suggest introducing a new method with this behavior (something like requireChecked). Unless I'm missing something, I would be willing to make a pull request for this, as it looks like it should be pretty straightforward. I just need some direction on which way this should be solved.

This relates to #298

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