Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonPaser#getString() returns wrong value #7

Open
glassfishrobot opened this issue Jun 9, 2015 · 10 comments
Open

JsonPaser#getString() returns wrong value #7

glassfishrobot opened this issue Jun 9, 2015 · 10 comments

Comments

@glassfishrobot
Copy link

The reference implementation fails to raise an error when the input JSON is invalid. Here is a reproducer:

JsonParser parser = Json.createParser(new StringReader("{"a":13"));
parser.next(); // START_OBJECT
parser.next(); // KEY_NAME
parser.next(); // VALUE_NUMBER
System.out.println(parser.getString()); // "13a":1

Environment

JDK7

Affected Versions

[1.0.4]

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Reported by jspiegel

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Was assigned to kchung

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
ren.zhijun.oracle said:
I tested with 1.1.0-SNAPSHOT implementation, and the output is (is this your expected):

13,

not:

"13a":1

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
jspiegel said:
I assume you mean the result is "13" and not "13,"?

13 would be acceptable as long as an additional call to parser.next() raises a parse error since the input is missing the final right curly bracket.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
ren.zhijun.oracle said:
Yes, the out put is 13

and an extra parser.next() throw exception like:
Exception in thread "main" java.util.NoSuchElementException
at org.glassfish.json.JsonParserImpl.next(JsonParserImpl.java:351)
at Jsonp29.main(Jsonp29.java:12)

So I will close the bug, do you agree?

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
jspiegel said:
It should raise JsonParsingException with a message that is helpful to the user.

https://json-processing-spec.java.net/nonav/releases/1.0/pfd-draft/javadocs/javax/json/stream/JsonParser.html#next(
Throws:
JsonParsingException - if the parser encounters invalid JSON when advancing to next state.

Most parsers would give a message like "Unexpected end of input. Expected '}' or ','" Or something like this. And ideally this message would include the line and column where the error was encountered.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JSONP-29

@glassfishrobot
Copy link
Author

@m0mus Commented
Changing it to enhancement.

@glassfishrobot
Copy link
Author

@lukasj lukasj transferred this issue from jakartaee/jsonp-api Jun 8, 2021
@jbescos
Copy link
Member

jbescos commented Feb 21, 2024

Right now this test is passing:

    public void testIssue7() {
        JsonParser parser = Json.createParser(new StringReader("{\"a\":13"));
        parser.next();
        parser.next();
        parser.next();
        assertEquals("13", parser.getString());
        try {
            parser.next();
            fail("Error expected");
        } catch (JsonParsingException e) {}
    }

It looks correct to my eyes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants