Skip to content

Commit 5c99090

Browse files
authored
Revert "Fixes #1173: column/offset locations wrong for many error conditions" (#1214)
1 parent e4da442 commit 5c99090

File tree

7 files changed

+4
-72
lines changed

7 files changed

+4
-72
lines changed

release-notes/CREDITS-2.x

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,4 @@ Mario Fusco (@mariofusco)
409409
Paul Bunyan (@hal7df)
410410
* Reported #1173: `JsonLocation` consistently off by one character for many invalid
411411
JSON parsing cases
412-
(2.16.2)
412+
(2.17.0)

release-notes/VERSION-2.x

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ a pure JSON library.
1616

1717
2.16.2 (not yet released)
1818

19-
#1173: `JsonLocation` consistently off by one character for many invalid JSON
20-
parsing cases
21-
(reported by Paul B)
19+
-
2220

2321
2.16.1 (24-Dec-2023)
2422

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

-17
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ public final JsonToken nextToken() throws IOException
769769
case '}':
770770
// Error: } is not valid at this point; valid closers have
771771
// been handled earlier
772-
--_inputPtr; // for correct error reporting
773772
_reportUnexpectedChar(i, "expected a value");
774773
case 't':
775774
_matchTrue();
@@ -1456,7 +1455,6 @@ private final JsonToken _parseFloat(int ch, int startPtr, int ptr, boolean neg,
14561455
// must be followed by sequence of ints, one minimum
14571456
if (fractLen == 0) {
14581457
if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
1459-
--_inputPtr; // for correct error reporting
14601458
_reportUnexpectedNumberChar(ch, "Decimal point not followed by a digit");
14611459
}
14621460
}
@@ -1486,7 +1484,6 @@ private final JsonToken _parseFloat(int ch, int startPtr, int ptr, boolean neg,
14861484
}
14871485
// must be followed by sequence of ints, one minimum
14881486
if (expLen == 0) {
1489-
--_inputPtr; // for correct error reporting
14901487
_reportUnexpectedNumberChar(ch, "Exponent indicator not followed by a digit");
14911488
}
14921489
}
@@ -1647,7 +1644,6 @@ private final JsonToken _parseNumber2(boolean neg, int startPtr) throws IOExcept
16471644
// must be followed by sequence of ints, one minimum
16481645
if (fractLen == 0) {
16491646
if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
1650-
--_inputPtr; // for correct error reporting
16511647
_reportUnexpectedNumberChar(c, "Decimal point not followed by a digit");
16521648
}
16531649
}
@@ -1692,7 +1688,6 @@ private final JsonToken _parseNumber2(boolean neg, int startPtr) throws IOExcept
16921688
}
16931689
// must be followed by sequence of ints, one minimum
16941690
if (expLen == 0) {
1695-
--_inputPtr; // for correct error reporting
16961691
_reportUnexpectedNumberChar(c, "Exponent indicator not followed by a digit");
16971692
}
16981693
}
@@ -1793,13 +1788,11 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean negative, fi
17931788
}
17941789
}
17951790
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !negative) {
1796-
--_inputPtr; // for correct error reporting
17971791
_reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow");
17981792
}
17991793
final String message = negative ?
18001794
"expected digit (0-9) to follow minus sign, for valid numeric value" :
18011795
"expected digit (0-9) for valid numeric value";
1802-
--_inputPtr; // for correct error reporting
18031796
_reportUnexpectedNumberChar(ch, message);
18041797
return null;
18051798
}
@@ -1947,7 +1940,6 @@ protected String _handleOddName(int i) throws IOException
19471940
}
19481941
// [JACKSON-69]: allow unquoted names if feature enabled:
19491942
if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) {
1950-
--_inputPtr; // for correct error reporting
19511943
_reportUnexpectedChar(i, "was expecting double-quote to start field name");
19521944
}
19531945
final int[] codes = CharTypes.getInputCodeLatin1JsNames();
@@ -1962,7 +1954,6 @@ protected String _handleOddName(int i) throws IOException
19621954
firstOk = Character.isJavaIdentifierPart((char) i);
19631955
}
19641956
if (!firstOk) {
1965-
--_inputPtr; // for correct error reporting
19661957
_reportUnexpectedChar(i, "was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name");
19671958
}
19681959
int ptr = _inputPtr;
@@ -2094,7 +2085,6 @@ protected JsonToken _handleOddValue(int i) throws IOException
20942085
_reportInvalidToken(""+((char) i), _validJsonTokenList());
20952086
}
20962087
// but if it doesn't look like a token:
2097-
--_inputPtr; // for correct error reporting
20982088
_reportUnexpectedChar(i, "expected a valid value "+_validJsonValueList());
20992089
return null;
21002090
}
@@ -2397,7 +2387,6 @@ private final int _skipColon2(boolean gotColon) throws IOException
23972387
return i;
23982388
}
23992389
if (i != INT_COLON) {
2400-
--_inputPtr; // for correct error reporting
24012390
_reportUnexpectedChar(i, "was expecting a colon to separate field name and value");
24022391
}
24032392
gotColon = true;
@@ -2471,7 +2460,6 @@ private final int _skipColonFast(int ptr) throws IOException
24712460
private final int _skipComma(int i) throws IOException
24722461
{
24732462
if (i != INT_COMMA) {
2474-
--_inputPtr; // for correct error reporting
24752463
_reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries");
24762464
}
24772465
while (_inputPtr < _inputEnd) {
@@ -2614,7 +2602,6 @@ private int _skipWSOrEnd2() throws IOException
26142602
private void _skipComment() throws IOException
26152603
{
26162604
if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) {
2617-
--_inputPtr; // for correct error reporting
26182605
_reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
26192606
}
26202607
// First: check which comment (if either) it is:
@@ -2627,7 +2614,6 @@ private void _skipComment() throws IOException
26272614
} else if (c == '*') {
26282615
_skipCComment();
26292616
} else {
2630-
--_inputPtr; // for correct error reporting
26312617
_reportUnexpectedChar(c, "was expecting either '*' or '/' for a comment");
26322618
}
26332619
}
@@ -2739,7 +2725,6 @@ protected char _decodeEscaped() throws IOException
27392725
int ch = (int) _inputBuffer[_inputPtr++];
27402726
int digit = CharTypes.charToHex(ch);
27412727
if (digit < 0) {
2742-
--_inputPtr; // for correct error reporting
27432728
_reportUnexpectedChar(ch, "expected a hex-digit for character escape sequence");
27442729
}
27452730
value = (value << 4) | digit;
@@ -3067,7 +3052,6 @@ private void _closeScope(int i) throws JsonParseException {
30673052
if (i == INT_RBRACKET) {
30683053
_updateLocation();
30693054
if (!_parsingContext.inArray()) {
3070-
--_inputPtr; // for correct error reporting
30713055
_reportMismatchedEndMarker(i, '}');
30723056
}
30733057
_parsingContext = _parsingContext.clearAndGetParent();
@@ -3076,7 +3060,6 @@ private void _closeScope(int i) throws JsonParseException {
30763060
if (i == INT_RCURLY) {
30773061
_updateLocation();
30783062
if (!_parsingContext.inObject()) {
3079-
--_inputPtr; // for correct error reporting
30803063
_reportMismatchedEndMarker(i, ']');
30813064
}
30823065
_parsingContext = _parsingContext.clearAndGetParent();

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

-17
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,6 @@ public JsonToken nextToken() throws IOException
779779
// Nope: do we then expect a comma?
780780
if (_parsingContext.expectComma()) {
781781
if (i != INT_COMMA) {
782-
--_inputPtr; // for correct error reporting
783782
_reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries");
784783
}
785784
i = _skipWS();
@@ -978,7 +977,6 @@ public boolean nextFieldName(SerializableString str) throws IOException
978977
// Nope: do we then expect a comma?
979978
if (_parsingContext.expectComma()) {
980979
if (i != INT_COMMA) {
981-
--_inputPtr; // for correct error reporting
982980
_reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries");
983981
}
984982
i = _skipWS();
@@ -1064,7 +1062,6 @@ public String nextFieldName() throws IOException
10641062
// Nope: do we then expect a comma?
10651063
if (_parsingContext.expectComma()) {
10661064
if (i != INT_COMMA) {
1067-
--_inputPtr; // for correct error reporting
10681065
_reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries");
10691066
}
10701067
i = _skipWS();
@@ -1688,7 +1685,6 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c,
16881685
// must be followed by sequence of ints, one minimum
16891686
if (fractLen == 0) {
16901687
if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) {
1691-
--_inputPtr; // for correct error reporting
16921688
_reportUnexpectedNumberChar(c, "Decimal point not followed by a digit");
16931689
}
16941690
}
@@ -1736,7 +1732,6 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c,
17361732
}
17371733
// must be followed by sequence of ints, one minimum
17381734
if (expLen == 0) {
1739-
--_inputPtr; // for correct error reporting
17401735
_reportUnexpectedNumberChar(c, "Exponent indicator not followed by a digit");
17411736
}
17421737
}
@@ -2149,7 +2144,6 @@ protected String _handleOddName(int ch) throws IOException
21492144
// Allow unquoted names if feature enabled:
21502145
if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) {
21512146
char c = (char) _decodeCharForError(ch);
2152-
--_inputPtr; // for correct error reporting
21532147
_reportUnexpectedChar(c, "was expecting double-quote to start field name");
21542148
}
21552149
/* Also: note that although we use a different table here,
@@ -2159,7 +2153,6 @@ protected String _handleOddName(int ch) throws IOException
21592153
final int[] codes = CharTypes.getInputCodeUtf8JsNames();
21602154
// Also: must start with a valid character...
21612155
if (codes[ch] != 0) {
2162-
--_inputPtr; // for correct error reporting
21632156
_reportUnexpectedChar(ch, "was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name");
21642157
}
21652158

@@ -2765,7 +2758,6 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
27652758
case '}':
27662759
// Error: neither is valid at this point; valid closers have
27672760
// been handled earlier
2768-
--_inputPtr; // for correct error reporting
27692761
_reportUnexpectedChar(c, "expected a value");
27702762
case '\'':
27712763
if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) {
@@ -2799,7 +2791,6 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
27992791
_reportInvalidToken(""+((char) c), _validJsonTokenList());
28002792
}
28012793
// but if it doesn't look like a token:
2802-
--_inputPtr; // for correct error reporting
28032794
_reportUnexpectedChar(c, "expected a valid value "+_validJsonValueList());
28042795
return null;
28052796
}
@@ -2932,13 +2923,11 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean neg, final b
29322923
match);
29332924
}
29342925
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !neg) {
2935-
--_inputPtr; // for correct error reporting
29362926
_reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow");
29372927
}
29382928
final String message = neg ?
29392929
"expected digit (0-9) to follow minus sign, for valid numeric value" :
29402930
"expected digit (0-9) for valid numeric value";
2941-
--_inputPtr; // for correct error reporting
29422931
_reportUnexpectedNumberChar(ch, message);
29432932
return null;
29442933
}
@@ -3264,7 +3253,6 @@ private final int _skipColon2(boolean gotColon) throws IOException
32643253
return i;
32653254
}
32663255
if (i != INT_COLON) {
3267-
--_inputPtr; // for correct error reporting
32683256
_reportUnexpectedChar(i, "was expecting a colon to separate field name and value");
32693257
}
32703258
gotColon = true;
@@ -3287,7 +3275,6 @@ private final int _skipColon2(boolean gotColon) throws IOException
32873275
private final void _skipComment() throws IOException
32883276
{
32893277
if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) {
3290-
--_inputPtr; // for correct error reporting
32913278
_reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)");
32923279
}
32933280
// First: check which comment (if either) it is:
@@ -3300,7 +3287,6 @@ private final void _skipComment() throws IOException
33003287
} else if (c == INT_ASTERISK) {
33013288
_skipCComment();
33023289
} else {
3303-
--_inputPtr; // for correct error reporting
33043290
_reportUnexpectedChar(c, "was expecting either '*' or '/' for a comment");
33053291
}
33063292
}
@@ -3446,7 +3432,6 @@ protected char _decodeEscaped() throws IOException
34463432
int ch = _inputBuffer[_inputPtr++];
34473433
int digit = CharTypes.charToHex(ch);
34483434
if (digit < 0) {
3449-
--_inputPtr; // for correct error reporting
34503435
_reportUnexpectedChar(ch & 0xFF, "expected a hex-digit for character escape sequence");
34513436
}
34523437
value = (value << 4) | digit;
@@ -3938,7 +3923,6 @@ private final JsonToken _closeScope(int i) throws JsonParseException {
39383923
private final void _closeArrayScope() throws JsonParseException {
39393924
_updateLocation();
39403925
if (!_parsingContext.inArray()) {
3941-
--_inputPtr; // for correct error reporting
39423926
_reportMismatchedEndMarker(']', '}');
39433927
}
39443928
_parsingContext = _parsingContext.clearAndGetParent();
@@ -3947,7 +3931,6 @@ private final void _closeArrayScope() throws JsonParseException {
39473931
private final void _closeObjectScope() throws JsonParseException {
39483932
_updateLocation();
39493933
if (!_parsingContext.inObject()) {
3950-
--_inputPtr; // for correct error reporting
39513934
_reportMismatchedEndMarker('}', ']');
39523935
}
39533936
_parsingContext = _parsingContext.clearAndGetParent();

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParserBase.java

-2
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ protected final JsonToken _startObjectScope() throws IOException
597597
protected final JsonToken _closeArrayScope() throws IOException
598598
{
599599
if (!_parsingContext.inArray()) {
600-
--_inputPtr; // for correct error reporting
601600
_reportMismatchedEndMarker(']', '}');
602601
}
603602
JsonReadContext ctxt = _parsingContext.getParent();
@@ -618,7 +617,6 @@ protected final JsonToken _closeArrayScope() throws IOException
618617
protected final JsonToken _closeObjectScope() throws IOException
619618
{
620619
if (!_parsingContext.inObject()) {
621-
--_inputPtr; // for correct error reporting
622620
_reportMismatchedEndMarker('}', ']');
623621
}
624622
JsonReadContext ctxt = _parsingContext.getParent();

0 commit comments

Comments
 (0)