Search in sources :

Example 21 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class CoreJDKSerializabilityTest method testParseException.

public void testParseException() throws Exception {
    JsonFactory jf = new JsonFactory();
    JsonParser p = jf.createParser(ObjectReadContext.empty(), "  { garbage! }");
    StreamReadException exc = null;
    try {
        p.nextToken();
        p.nextToken();
        fail("Should not get here");
    } catch (StreamReadException e) {
        exc = e;
    }
    p.close();
    byte[] stuff = jdkSerialize(exc);
    StreamReadException result = jdkDeserialize(stuff);
    assertNotNull(result);
}
Also used : JsonFactory(com.fasterxml.jackson.core.json.JsonFactory) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 22 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class ParserErrorHandling679Test method _testNonRootMangledInts.

private void _testNonRootMangledInts(int mode, String value) throws Exception {
    // Also test with floats
    JsonParser p = createParser(mode, "[ " + value + " ]");
    assertEquals(JsonToken.START_ARRAY, p.nextToken());
    try {
        JsonToken t = p.nextToken();
        int v = p.getIntValue();
        fail("Should have gotten an exception for '" + value + "'; instead got (" + t + ") number: " + v);
    } catch (StreamReadException e) {
        verifyException(e, "expected ");
    }
    p.close();
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 23 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-core by FasterXML.

the class AsyncTokenErrorTest method testMangledNonRootInts.

public void testMangledNonRootInts() {
    AsyncReaderWrapper p = _createParser("[ 123true ]");
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t);
    } catch (StreamReadException e) {
        verifyException(e, "expected space");
    }
    p.close();
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 24 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class UncaughtException303Test method testUncaughtException303.

// [dataformats-binary#303]
@Test
public void testUncaughtException303() throws Exception {
    URL poc = getClass().getResource("/data/issue-303.ion");
    try {
        MAPPER.readTree(poc);
        fail("Should not pass with invalid content");
    } catch (StreamReadException e) {
        // !!! TODO: change to match what we actually expect
        verifyException(e, "MATCH MESSAGE");
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) URL(java.net.URL) Test(org.junit.Test)

Example 25 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class Fuzz272_32722_ChunkedTextTest method testChunkedWithUTF8_4Bytes.

// [dataformats-binary#272]
public void testChunkedWithUTF8_4Bytes() throws Exception {
    final byte[] input = new byte[] { // text, chunked (length marker 0x1F)
    (byte) 0x7F, // text segment of 0 bytes. Legal but weird
    0x60, // "simple value" 16, reported as "int" 16.
    (byte) 0xF0, // ... whatever this would be, fuzzer playing with stuff
    0x70 };
    try (JsonParser p = MAPPER.createParser(input)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            p.getText();
            fail("Should not pass, invalid content");
        } catch (StreamReadException e) {
            verifyException(e, "Mismatched chunk in chunked content");
            verifyException(e, "(byte 0xF0)");
        }
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

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