Skip to content

Commit e4da442

Browse files
authored
Add test showing regression wrt #1173 fix (inability to recover from certain parse errors) (#1213)
1 parent 7df89c4 commit e4da442

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.core.*;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
// Test(s) to see that limited amount of recovery is possible over
10+
// content: specifically, most single-character problems.
11+
public class ParserErrorRecovery1173Test
12+
extends JUnit5TestBase
13+
{
14+
private final JsonFactory JSON_F = newStreamFactory();
15+
16+
@Test
17+
public void testRecoverNumberBytes() throws Exception {
18+
_testRecoverNumber(MODE_INPUT_STREAM);
19+
_testRecoverNumber(MODE_INPUT_STREAM_THROTTLED);
20+
}
21+
22+
@Test
23+
public void testRecoverNumberDataInput() throws Exception {
24+
_testRecoverNumber(MODE_DATA_INPUT);
25+
}
26+
27+
@Test
28+
public void testRecoverNumberChars() throws Exception {
29+
_testRecoverNumber(MODE_READER);
30+
_testRecoverNumber(MODE_READER_THROTTLED);
31+
}
32+
33+
/*
34+
/**********************************************************
35+
/* Helper methods
36+
/**********************************************************
37+
*/
38+
39+
private void _testRecoverNumber(int mode) throws Exception
40+
{
41+
try (JsonParser p = createParser(JSON_F, mode, "1\n[ , ]\n3")) {
42+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
43+
assertEquals(1, p.getIntValue());
44+
assertToken(JsonToken.START_ARRAY, p.nextToken());
45+
try {
46+
JsonToken t = p.nextToken();
47+
fail("Should have gotten an exception; instead got token: "+t);
48+
} catch (JsonParseException e) {
49+
verifyException(e, "Unexpected character (','");
50+
}
51+
52+
// But should essentially "skip" problematic character
53+
assertToken(JsonToken.END_ARRAY, p.nextToken());
54+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
55+
assertEquals(3, p.getIntValue());
56+
assertNull(p.nextToken());
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)