-
-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test showing regression wrt #1173 fix (inability to recover from …
…certain parse errors) (#1213)
- Loading branch information
1 parent
7df89c4
commit e4da442
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/test/java/com/fasterxml/jackson/failing/ParserErrorRecovery1173Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.core.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
// Test(s) to see that limited amount of recovery is possible over | ||
// content: specifically, most single-character problems. | ||
public class ParserErrorRecovery1173Test | ||
extends JUnit5TestBase | ||
{ | ||
private final JsonFactory JSON_F = newStreamFactory(); | ||
|
||
@Test | ||
public void testRecoverNumberBytes() throws Exception { | ||
_testRecoverNumber(MODE_INPUT_STREAM); | ||
_testRecoverNumber(MODE_INPUT_STREAM_THROTTLED); | ||
} | ||
|
||
@Test | ||
public void testRecoverNumberDataInput() throws Exception { | ||
_testRecoverNumber(MODE_DATA_INPUT); | ||
} | ||
|
||
@Test | ||
public void testRecoverNumberChars() throws Exception { | ||
_testRecoverNumber(MODE_READER); | ||
_testRecoverNumber(MODE_READER_THROTTLED); | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Helper methods | ||
/********************************************************** | ||
*/ | ||
|
||
private void _testRecoverNumber(int mode) throws Exception | ||
{ | ||
try (JsonParser p = createParser(JSON_F, mode, "1\n[ , ]\n3")) { | ||
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); | ||
assertEquals(1, p.getIntValue()); | ||
assertToken(JsonToken.START_ARRAY, p.nextToken()); | ||
try { | ||
JsonToken t = p.nextToken(); | ||
fail("Should have gotten an exception; instead got token: "+t); | ||
} catch (JsonParseException e) { | ||
verifyException(e, "Unexpected character (','"); | ||
} | ||
|
||
// But should essentially "skip" problematic character | ||
assertToken(JsonToken.END_ARRAY, p.nextToken()); | ||
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken()); | ||
assertEquals(3, p.getIntValue()); | ||
assertNull(p.nextToken()); | ||
} | ||
} | ||
} |