Search in sources :

Example 66 with StreamReadException

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();
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 67 with StreamReadException

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();
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 68 with StreamReadException

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");
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Aggregations

StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)68 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)23 JsonParser (com.fasterxml.jackson.core.JsonParser)15 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)11 CBORParser (com.fasterxml.jackson.dataformat.cbor.CBORParser)9 JsonToken (com.fasterxml.jackson.core.JsonToken)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayFeeder (com.fasterxml.jackson.core.async.ByteArrayFeeder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URL (java.net.URL)2 Test (org.junit.Test)2 InputCoercionException (com.fasterxml.jackson.core.exc.InputCoercionException)1 WrappedIOException (com.fasterxml.jackson.core.exc.WrappedIOException)1 FilteringParserDelegate (com.fasterxml.jackson.core.filter.FilteringParserDelegate)1 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SmileGenerator (com.fasterxml.jackson.dataformat.smile.SmileGenerator)1 SmileMapper (com.fasterxml.jackson.dataformat.smile.databind.SmileMapper)1 ThrottledInputStream (com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream)1