Skip to content

Parsing JSON with ALLOW_MISSING_VALUE enabled results in endless stream of VALUE_NULL tokens #616

Closed
@jusliu

Description

@jusliu
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonParser.Feature;
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;

public class Test {
	public static void main(String[] args) {
		String content = ",";
		JsonFactory f = new JsonFactory().configure(Feature.ALLOW_MISSING_VALUES, true);
		try {
			JsonParser parser = f.createJsonParser(content);
			JsonToken current = parser.nextToken();

			// this will result in an infinite loop
			while (parser.hasCurrentToken()) {
				System.out.println(current); // prints VALUE_NULL
				current = parser.nextToken();
			}
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

This code results in an infinite loop. Only happens with ALLOW_MISSING_VALUES enabled. Treats the unexpected comma as a missing value or something, replacing it with NULL, but on the top-level this results in an infinite loop where nextToken() will return VALUE_NULL forever.

Also happens on inputs including:

  1. [],
  2. {"foo": "bar"},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions