Skip to content

Commit

Permalink
Add test showing regression wrt #1173 fix (inability to recover from …
Browse files Browse the repository at this point in the history
…certain parse errors) (#1213)
  • Loading branch information
cowtowncoder committed Feb 11, 2024
1 parent 7df89c4 commit e4da442
Showing 1 changed file with 59 additions and 0 deletions.
@@ -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());
}
}
}

0 comments on commit e4da442

Please sign in to comment.