Skip to content

NullPointerExceptions parsing non-strict JSON using JSONTokener from version 20241224 #933

Description

@bherw
String s = "{\"a\": [],}";
var tokener = new JSONTokener(s);
var value = tokener.nextValue();
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.json.JSONParserConfiguration.isStrictMode()" because "jsonParserConfiguration" is null
	at org.json.JSONObject.<init>(JSONObject.java:280)
	at org.json.JSONTokener.nextValue(JSONTokener.java:429)
	at Scratch.main(scratch_3.java:8)
String s = "[1,]";
var tokener = new JSONTokener(s);
var value = tokener.nextValue();
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.json.JSONParserConfiguration.isStrictMode()" because "jsonParserConfiguration" is null
	at org.json.JSONArray.<init>(JSONArray.java:144)
	at org.json.JSONTokener.nextValue(JSONTokener.java:436)
	at Scratch.main(scratch_3.java:8)

It looks like the parsing implementations in the JSONObject and JSONArray constructors that take a JSONTokener don't check if the configuration is null when encountering non-standard JSON input.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions