Skip to content

Inconsistency in JsonParser#hasNext() #24

@leadpony

Description

@leadpony

hasNext() method in JsonParser provided by the Reference Implementation does not behave consistently for unterminated JSON.
Please see the following results.

No. JSON to parse Result of hasNext()
1 (empty) hasNext(); // returns true 😕
2 { next();
hasNext(); // throws JsonParsingException
3 {"a" next();
next();
hasNext(); // throws JsonParsingException
4 {"a": next();
next();
hasNext(); // returns true 😕
5 {"a":1 next();
next();
next();
hasNext(); // throws JsonParsingException
6 {"a":1, next();
next();
next();
hasNext(); // returns true 😕
7 [ next();
hasNext(); // throws JsonParsingException
8 [1 next();
next();
hasNext(); // throws JsonParsingException
9 [1, next();
next();
hasNext(); // returns true 😕

I believe for No.1, 4, 6, and 9 case, hasNext() should throw JsonParsingException instead of returning true.
Are these correct and intended bahavior?

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