use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class JsonLocationTest method testDisableSourceInclusion.
// for [jackson-core#356]
public void testDisableSourceInclusion() {
JsonFactory f = JsonFactory.builder().disable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION).build();
JsonParser p = f.createParser(ObjectReadContext.empty(), "[ foobar ]");
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
fail("Shouldn't have passed");
} catch (StreamReadException e) {
verifyException(e, "unrecognized token");
JsonLocation loc = e.getLocation();
assertNull(loc.contentReference().getRawContent());
assertEquals("UNKNOWN", loc.sourceDescription());
}
p.close();
// and verify same works for byte-based too
p = f.createParser(ObjectReadContext.empty(), utf8Bytes("[ foobar ]"));
assertToken(JsonToken.START_ARRAY, p.nextToken());
try {
p.nextToken();
fail("Shouldn't have passed");
} catch (StreamReadException e) {
verifyException(e, "unrecognized token");
JsonLocation loc = e.getLocation();
assertNull(loc.contentReference().getRawContent());
assertEquals("UNKNOWN", loc.sourceDescription());
}
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.
the class Fuzz34435ParseTest method testFuzz34435ViaParser.
public void testFuzz34435ViaParser() throws Exception {
final JsonFactory f = JsonFactory.builder().enable(JsonReadFeature.ALLOW_JAVA_COMMENTS).enable(JsonReadFeature.ALLOW_YAML_COMMENTS).enable(JsonReadFeature.ALLOW_SINGLE_QUOTES).enable(JsonReadFeature.ALLOW_UNQUOTED_PROPERTY_NAMES).build();
JsonParser p = f.createParser(ObjectReadContext.empty(), DOC);
// Long doc so only check a few initial entries first:
for (int i = 0; i < 10; ++i) {
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
}
// Beyond that, simply read through to catch expected issue
try {
while (p.nextToken() != null) {
// but force decoding of Strings
switch(p.currentToken()) {
case PROPERTY_NAME:
p.currentName();
break;
case VALUE_STRING:
p.getText();
break;
default:
}
}
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Unexpected character");
verifyException(e, "colon to separate");
}
p.close();
}
use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformat-xml by FasterXML.
the class Fuzz465_32906_CDataReadTest method testIssue465.
public void testIssue465() throws Exception {
byte[] doc = readResource("/data/fuzz-32906.xml");
try {
JsonNode root = MAPPER.readTree(doc);
fail("Should not pass, got: " + root);
} catch (StreamReadException e) {
verifyException(e, "Unexpected EOF in CDATA");
}
}
Aggregations