Skip to content

Commit de04d86

Browse files
committed
Merge branch '3.0' into 3.x
2 parents b4af9e7 + 2135778 commit de04d86

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

src/test/java/tools/jackson/core/unittest/tofix/async/AsyncParserNonRootTokenTest.java renamed to src/test/java/tools/jackson/core/unittest/tofix/async/AsyncTokenBranchErrorTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
import static org.junit.jupiter.api.Assertions.fail;
1313

14-
class AsyncParserNonRootTokenTest extends AsyncTestBase
14+
// Tests for handling token decoding fails for non-Root values
15+
// (within Object / Array)
16+
class AsyncTokenBranchErrorTest extends AsyncTestBase
1517
{
1618
private final JsonFactory JSON_F = newStreamFactory();
1719

@@ -52,6 +54,15 @@ private void _doTestInvalidKeyword(String value)
5254
} catch (StreamReadException jex) {
5355
verifyException(jex, EXP_MAIN, EXP_ALT);
5456
}
57+
58+
// Try as root-level value as well:
59+
doc = value + " "; // may need space after for DataInput
60+
try (AsyncReaderWrapper p = _createParser(doc)) {
61+
p.nextToken();
62+
fail("Expected an exception for malformed value keyword");
63+
} catch (StreamReadException jex) {
64+
verifyException(jex, EXP_MAIN, EXP_ALT);
65+
}
5566
}
5667

5768
@JacksonTestFailureExpected
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package tools.jackson.core.unittest.tofix.async;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import tools.jackson.core.*;
6+
import tools.jackson.core.json.JsonFactory;
7+
import tools.jackson.core.exc.StreamReadException;
8+
import tools.jackson.core.unittest.async.AsyncTestBase;
9+
import tools.jackson.core.unittest.testutil.AsyncReaderWrapper;
10+
import tools.jackson.core.unittest.testutil.failure.JacksonTestFailureExpected;
11+
12+
import static org.junit.jupiter.api.Assertions.fail;
13+
14+
// Tests for handling token decoding fails for Root values
15+
class AsyncTokenRootErrorTest extends AsyncTestBase
16+
{
17+
private final JsonFactory JSON_F = newStreamFactory();
18+
19+
@JacksonTestFailureExpected
20+
@Test
21+
void mangledRootInts() throws Exception
22+
{
23+
try (AsyncReaderWrapper p = _createParser("123true")) {
24+
JsonToken t = p.nextToken();
25+
fail("Should have gotten an exception; instead got token: "+t+"; number: "+p.getNumberValue());
26+
} catch (StreamReadException e) {
27+
verifyException(e, "expected space");
28+
}
29+
}
30+
31+
@JacksonTestFailureExpected
32+
@Test
33+
void mangledRootFloats() throws Exception
34+
{
35+
// Also test with floats
36+
try (AsyncReaderWrapper p = _createParser("1.5false")) {
37+
JsonToken t = p.nextToken();
38+
fail("Should have gotten an exception; instead got token: "+t+"; number: "+p.getNumberValue());
39+
} catch (StreamReadException e) {
40+
verifyException(e, "expected space");
41+
}
42+
}
43+
44+
private AsyncReaderWrapper _createParser(String doc) throws Exception
45+
{
46+
return asyncForBytes(JSON_F, 1, _jsonDoc(doc), 1);
47+
}
48+
}

0 commit comments

Comments
 (0)