Search in sources :

Example 51 with StreamReadException

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

the class ParserInternalsTest method _verifyVIntBad.

private void _verifyVIntBad(byte[] doc, String... msgs) throws Exception {
    // First, read with no boundaries
    try (SmileParser p = _minimalParser(doc)) {
        try {
            int val = p._readUnsignedVInt();
            fail("Should not pass, got 0x" + Integer.toHexString(val));
        } catch (StreamReadException e) {
            verifyException(e, msgs);
        }
    }
    // Then incremental read
    try (SmileParser p = _minimalParser(new ThrottledInputStream(doc, 1))) {
        try {
            int val = p._readUnsignedVInt();
            fail("Should not pass, got 0x" + Integer.toHexString(val));
        } catch (StreamReadException e) {
            verifyException(e, msgs);
        }
    }
}
Also used : ThrottledInputStream(com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 52 with StreamReadException

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

the class ParserErrorHandling679Test method _testNonRootMangledFloats679.

private void _testNonRootMangledFloats679(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();
        Double v = p.getDoubleValue();
        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 53 with StreamReadException

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

the class AsyncTokenErrorTest method _doTestInvalidKeyword.

private void _doTestInvalidKeyword(String value) {
    String doc = "{ \"key1\" : " + value + " }";
    AsyncReaderWrapper p = _createParser(doc);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    // get the exception early or late...
    try {
        assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
        p.nextToken();
        fail("Expected an exception for malformed value keyword");
    } catch (StreamReadException jex) {
        verifyException(jex, "Unrecognized token");
        verifyException(jex, value);
    } finally {
        p.close();
    }
    // Try as root-level value as well:
    // may need space after for DataInput
    doc = value + " ";
    p = _createParser(doc);
    try {
        p.nextToken();
        fail("Expected an exception for malformed value keyword");
    } catch (StreamReadException jex) {
        verifyException(jex, "Unrecognized token");
        verifyException(jex, value);
    } finally {
        p.close();
    }
}
Also used : AsyncReaderWrapper(com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 54 with StreamReadException

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

the class AsyncTokenErrorTest method testMangledRootInts.

public void testMangledRootInts() {
    AsyncReaderWrapper p = _createParser("123true");
    try {
        JsonToken t = p.nextToken();
        fail("Should have gotten an exception; instead got token: " + t + "; number: " + p.getNumberValue());
    } 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 55 with StreamReadException

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

the class AsyncTokenErrorTest method testMangledNonRootFloats.

public void testMangledNonRootFloats() {
    AsyncReaderWrapper p = _createParser("[ 1.5false ]");
    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)

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