diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 22e08b2d1c..d5a7fb329f 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -409,4 +409,4 @@ Mario Fusco (@mariofusco) Paul Bunyan (@hal7df) * Reported #1173: `JsonLocation` consistently off by one character for many invalid JSON parsing cases - (2.16.2) + (2.17.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 9f7c44e607..3b5977a2eb 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,9 +16,7 @@ a pure JSON library. 2.16.2 (not yet released) -#1173: `JsonLocation` consistently off by one character for many invalid JSON - parsing cases - (reported by Paul B) +- 2.16.1 (24-Dec-2023) diff --git a/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java index 15e4bf4854..27b5cfec2a 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java @@ -769,7 +769,6 @@ public final JsonToken nextToken() throws IOException case '}': // Error: } is not valid at this point; valid closers have // been handled earlier - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "expected a value"); case 't': _matchTrue(); @@ -1456,7 +1455,6 @@ private final JsonToken _parseFloat(int ch, int startPtr, int ptr, boolean neg, // must be followed by sequence of ints, one minimum if (fractLen == 0) { if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Decimal point not followed by a digit"); } } @@ -1486,7 +1484,6 @@ private final JsonToken _parseFloat(int ch, int startPtr, int ptr, boolean neg, } // must be followed by sequence of ints, one minimum if (expLen == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Exponent indicator not followed by a digit"); } } @@ -1647,7 +1644,6 @@ private final JsonToken _parseNumber2(boolean neg, int startPtr) throws IOExcept // must be followed by sequence of ints, one minimum if (fractLen == 0) { if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(c, "Decimal point not followed by a digit"); } } @@ -1692,7 +1688,6 @@ private final JsonToken _parseNumber2(boolean neg, int startPtr) throws IOExcept } // must be followed by sequence of ints, one minimum if (expLen == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(c, "Exponent indicator not followed by a digit"); } } @@ -1793,13 +1788,11 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean negative, fi } } if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !negative) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } final String message = negative ? "expected digit (0-9) to follow minus sign, for valid numeric value" : "expected digit (0-9) for valid numeric value"; - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, message); return null; } @@ -1947,7 +1940,6 @@ protected String _handleOddName(int i) throws IOException } // [JACKSON-69]: allow unquoted names if feature enabled: if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting double-quote to start field name"); } final int[] codes = CharTypes.getInputCodeLatin1JsNames(); @@ -1962,7 +1954,6 @@ protected String _handleOddName(int i) throws IOException firstOk = Character.isJavaIdentifierPart((char) i); } if (!firstOk) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name"); } int ptr = _inputPtr; @@ -2094,7 +2085,6 @@ protected JsonToken _handleOddValue(int i) throws IOException _reportInvalidToken(""+((char) i), _validJsonTokenList()); } // but if it doesn't look like a token: - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "expected a valid value "+_validJsonValueList()); return null; } @@ -2397,7 +2387,6 @@ private final int _skipColon2(boolean gotColon) throws IOException return i; } if (i != INT_COLON) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting a colon to separate field name and value"); } gotColon = true; @@ -2471,7 +2460,6 @@ private final int _skipColonFast(int ptr) throws IOException private final int _skipComma(int i) throws IOException { if (i != INT_COMMA) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); } while (_inputPtr < _inputEnd) { @@ -2614,7 +2602,6 @@ private int _skipWSOrEnd2() throws IOException private void _skipComment() throws IOException { if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)"); } // First: check which comment (if either) it is: @@ -2627,7 +2614,6 @@ private void _skipComment() throws IOException } else if (c == '*') { _skipCComment(); } else { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c, "was expecting either '*' or '/' for a comment"); } } @@ -2739,7 +2725,6 @@ protected char _decodeEscaped() throws IOException int ch = (int) _inputBuffer[_inputPtr++]; int digit = CharTypes.charToHex(ch); if (digit < 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "expected a hex-digit for character escape sequence"); } value = (value << 4) | digit; @@ -3067,7 +3052,6 @@ private void _closeScope(int i) throws JsonParseException { if (i == INT_RBRACKET) { _updateLocation(); if (!_parsingContext.inArray()) { - --_inputPtr; // for correct error reporting _reportMismatchedEndMarker(i, '}'); } _parsingContext = _parsingContext.clearAndGetParent(); @@ -3076,7 +3060,6 @@ private void _closeScope(int i) throws JsonParseException { if (i == INT_RCURLY) { _updateLocation(); if (!_parsingContext.inObject()) { - --_inputPtr; // for correct error reporting _reportMismatchedEndMarker(i, ']'); } _parsingContext = _parsingContext.clearAndGetParent(); diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java index d28d632dc8..4f43c7eeb9 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java @@ -779,7 +779,6 @@ public JsonToken nextToken() throws IOException // Nope: do we then expect a comma? if (_parsingContext.expectComma()) { if (i != INT_COMMA) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); } i = _skipWS(); @@ -978,7 +977,6 @@ public boolean nextFieldName(SerializableString str) throws IOException // Nope: do we then expect a comma? if (_parsingContext.expectComma()) { if (i != INT_COMMA) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); } i = _skipWS(); @@ -1064,7 +1062,6 @@ public String nextFieldName() throws IOException // Nope: do we then expect a comma? if (_parsingContext.expectComma()) { if (i != INT_COMMA) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); } i = _skipWS(); @@ -1688,7 +1685,6 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c, // must be followed by sequence of ints, one minimum if (fractLen == 0) { if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(c, "Decimal point not followed by a digit"); } } @@ -1736,7 +1732,6 @@ private final JsonToken _parseFloat(char[] outBuf, int outPtr, int c, } // must be followed by sequence of ints, one minimum if (expLen == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(c, "Exponent indicator not followed by a digit"); } } @@ -2149,7 +2144,6 @@ protected String _handleOddName(int ch) throws IOException // Allow unquoted names if feature enabled: if ((_features & FEAT_MASK_ALLOW_UNQUOTED_NAMES) == 0) { char c = (char) _decodeCharForError(ch); - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c, "was expecting double-quote to start field name"); } /* Also: note that although we use a different table here, @@ -2159,7 +2153,6 @@ protected String _handleOddName(int ch) throws IOException final int[] codes = CharTypes.getInputCodeUtf8JsNames(); // Also: must start with a valid character... if (codes[ch] != 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name"); } @@ -2765,7 +2758,6 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException case '}': // Error: neither is valid at this point; valid closers have // been handled earlier - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c, "expected a value"); case '\'': if ((_features & FEAT_MASK_ALLOW_SINGLE_QUOTES) != 0) { @@ -2799,7 +2791,6 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException _reportInvalidToken(""+((char) c), _validJsonTokenList()); } // but if it doesn't look like a token: - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c, "expected a valid value "+_validJsonValueList()); return null; } @@ -2932,13 +2923,11 @@ protected JsonToken _handleInvalidNumberStart(int ch, final boolean neg, final b match); } if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature()) && hasSign && !neg) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } final String message = neg ? "expected digit (0-9) to follow minus sign, for valid numeric value" : "expected digit (0-9) for valid numeric value"; - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, message); return null; } @@ -3264,7 +3253,6 @@ private final int _skipColon2(boolean gotColon) throws IOException return i; } if (i != INT_COLON) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(i, "was expecting a colon to separate field name and value"); } gotColon = true; @@ -3287,7 +3275,6 @@ private final int _skipColon2(boolean gotColon) throws IOException private final void _skipComment() throws IOException { if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)"); } // First: check which comment (if either) it is: @@ -3300,7 +3287,6 @@ private final void _skipComment() throws IOException } else if (c == INT_ASTERISK) { _skipCComment(); } else { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c, "was expecting either '*' or '/' for a comment"); } } @@ -3446,7 +3432,6 @@ protected char _decodeEscaped() throws IOException int ch = _inputBuffer[_inputPtr++]; int digit = CharTypes.charToHex(ch); if (digit < 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch & 0xFF, "expected a hex-digit for character escape sequence"); } value = (value << 4) | digit; @@ -3938,7 +3923,6 @@ private final JsonToken _closeScope(int i) throws JsonParseException { private final void _closeArrayScope() throws JsonParseException { _updateLocation(); if (!_parsingContext.inArray()) { - --_inputPtr; // for correct error reporting _reportMismatchedEndMarker(']', '}'); } _parsingContext = _parsingContext.clearAndGetParent(); @@ -3947,7 +3931,6 @@ private final void _closeArrayScope() throws JsonParseException { private final void _closeObjectScope() throws JsonParseException { _updateLocation(); if (!_parsingContext.inObject()) { - --_inputPtr; // for correct error reporting _reportMismatchedEndMarker('}', ']'); } _parsingContext = _parsingContext.clearAndGetParent(); diff --git a/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParserBase.java b/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParserBase.java index 70cf7c2ae7..4eeb24ee95 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParserBase.java +++ b/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParserBase.java @@ -597,7 +597,6 @@ protected final JsonToken _startObjectScope() throws IOException protected final JsonToken _closeArrayScope() throws IOException { if (!_parsingContext.inArray()) { - --_inputPtr; // for correct error reporting _reportMismatchedEndMarker(']', '}'); } JsonReadContext ctxt = _parsingContext.getParent(); @@ -618,7 +617,6 @@ protected final JsonToken _closeArrayScope() throws IOException protected final JsonToken _closeObjectScope() throws IOException { if (!_parsingContext.inObject()) { - --_inputPtr; // for correct error reporting _reportMismatchedEndMarker('}', ']'); } JsonReadContext ctxt = _parsingContext.getParent(); diff --git a/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingUtf8JsonParserBase.java b/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingUtf8JsonParserBase.java index 55563b061c..de2f081380 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingUtf8JsonParserBase.java +++ b/src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingUtf8JsonParserBase.java @@ -527,7 +527,6 @@ private final JsonToken _startFieldNameAfterComma(int ch) throws IOException if (ch == INT_SLASH) { return _startSlashComment(MINOR_FIELD_LEADING_COMMA); } - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); } int ptr = _inputPtr; @@ -667,7 +666,6 @@ private final JsonToken _startValueExpectComma(int ch) throws IOException if (ch == INT_HASH) { return _finishHashComment(MINOR_VALUE_EXPECTING_COMMA); } - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "was expecting comma to separate "+_parsingContext.typeDesc()+" entries"); } @@ -762,7 +760,6 @@ private final JsonToken _startValueExpectColon(int ch) throws IOException return _finishHashComment(MINOR_VALUE_EXPECTING_COLON); } // can not omit colon here - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "was expecting a colon to separate field name and value"); } int ptr = _inputPtr; @@ -924,7 +921,6 @@ protected JsonToken _startUnexpectedValue(boolean leadingComma, int ch) throws I return _finishNonStdToken(NON_STD_TOKEN_INFINITY, 1); } // !!! TODO: maybe try to collect more information for better diagnostics - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "expected a valid value "+_validJsonValueList()); return null; } @@ -961,7 +957,6 @@ private final int _skipWS(int ch) throws IOException private final JsonToken _startSlashComment(int fromMinorState) throws IOException { if ((_features & FEAT_MASK_ALLOW_JAVA_COMMENTS) == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar('/', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)"); } @@ -978,7 +973,6 @@ private final JsonToken _startSlashComment(int fromMinorState) throws IOExceptio if (ch == INT_SLASH) { // c++-style return _finishCppComment(fromMinorState); } - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch & 0xFF, "was expecting either '*' or '/' for a comment"); return null; } @@ -987,7 +981,6 @@ private final JsonToken _finishHashComment(int fromMinorState) throws IOExceptio { // Could by-pass this check by refactoring, but for now simplest way... if ((_features & FEAT_MASK_ALLOW_YAML_COMMENTS) == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar('#', "maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_YAML_COMMENTS' not enabled for parser)"); } while (true) { @@ -1351,13 +1344,11 @@ protected JsonToken _startNegativeNumber() throws IOException return _finishNumberLeadingNegZeroes(); } // One special case: if first char is 0, must not be followed by a digit - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value"); } else if (ch > INT_9) { if (ch == 'I') { return _finishNonStdToken(NON_STD_TOKEN_MINUS_INFINITY, 2); } - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value"); } char[] outBuf = _textBuffer.emptyAndGetCurrentSegment(); @@ -1417,23 +1408,19 @@ protected JsonToken _startPositiveNumber() throws IOException if (ch <= INT_0) { if (ch == INT_0) { if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } return _finishNumberLeadingPosZeroes(); } // One special case: if first char is 0, must not be followed by a digit - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow plus sign, for valid numeric value"); } else if (ch > INT_9) { if (ch == 'I') { return _finishNonStdToken(NON_STD_TOKEN_PLUS_INFINITY, 2); } - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow plus sign, for valid numeric value"); } if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } char[] outBuf = _textBuffer.emptyAndGetCurrentSegment(); @@ -1516,7 +1503,6 @@ protected JsonToken _startNumberLeadingZero() throws IOException // (colon not possible since this is within value, not after key) // if ((ch != INT_RBRACKET) && (ch != INT_RCURLY)) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9), decimal point (.) or exponent indicator (e/E) to follow '0'"); } @@ -1546,7 +1532,6 @@ protected JsonToken _finishNumberPlusMinus(final int ch, final boolean negative) return _finishNumberLeadingNegZeroes(); } else { if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } return _finishNumberLeadingPosZeroes(); @@ -1557,7 +1542,6 @@ protected JsonToken _finishNumberPlusMinus(final int ch, final boolean negative) return _finishNumberLeadingNegZeroes(); } else { if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar('+', "JSON spec does not allow numbers to have plus signs: enable `JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS` to allow"); } _inputPtr--; @@ -1567,7 +1551,6 @@ protected JsonToken _finishNumberPlusMinus(final int ch, final boolean negative) final String message = negative ? "expected digit (0-9) to follow minus sign, for valid numeric value" : "expected digit (0-9) for valid numeric value"; - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, message); } else if (ch > INT_9) { if (ch == 'I') { @@ -1577,7 +1560,6 @@ protected JsonToken _finishNumberPlusMinus(final int ch, final boolean negative) final String message = negative ? "expected digit (0-9) to follow minus sign, for valid numeric value" : "expected digit (0-9) for valid numeric value"; - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, message); } if (!negative && !isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) { @@ -1618,7 +1600,6 @@ protected JsonToken _finishNumberLeadingZeroes() throws IOException // (colon not possible since this is within value, not after key) // if ((ch != INT_RBRACKET) && (ch != INT_RCURLY)) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9), decimal point (.) or exponent indicator (e/E) to follow '0'"); } @@ -1679,7 +1660,6 @@ protected JsonToken _finishNumberLeadingPosNegZeroes(final boolean negative) thr // (colon not possible since this is within value, not after key) // if ((ch != INT_RBRACKET) && (ch != INT_RCURLY)) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "expected digit (0-9), decimal point (.) or exponent indicator (e/E) to follow '0'"); } @@ -1764,7 +1744,6 @@ protected JsonToken _startFloat(char[] outBuf, int outPtr, int ch) throws IOExce // must be followed by sequence of ints, one minimum if (fractLen == 0) { if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Decimal point not followed by a digit"); } } @@ -1821,7 +1800,6 @@ protected JsonToken _startFloat(char[] outBuf, int outPtr, int ch) throws IOExce // must be followed by sequence of ints, one minimum ch &= 0xFF; if (expLen == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Exponent indicator not followed by a digit"); } } @@ -1856,10 +1834,8 @@ protected JsonToken _finishFloatFraction() throws IOException } ch = getNextSignedByteFromBuffer(); } else if (ch == 'f' || ch == 'd' || ch == 'F' || ch == 'D') { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "JSON does not support parsing numbers that have 'f' or 'd' suffixes"); } else if (ch == INT_PERIOD) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Cannot parse number with more than one decimal point"); } else { loop = false; @@ -1870,7 +1846,6 @@ protected JsonToken _finishFloatFraction() throws IOException // must be followed by sequence of ints, one minimum if (fractLen == 0) { if (!isEnabled(JsonReadFeature.ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS.mappedFeature())) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Decimal point not followed by a digit"); } } @@ -1932,7 +1907,6 @@ protected JsonToken _finishFloatExponent(boolean checkSign, int ch) throws IOExc // must be followed by sequence of ints, one minimum ch &= 0xFF; if (expLen == 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedNumberChar(ch, "Exponent indicator not followed by a digit"); } // push back the last char @@ -2240,7 +2214,6 @@ private JsonToken _handleOddName(int ch) throws IOException // !!! TODO: Decode UTF-8 characters properly... // char c = (char) _decodeCharForError(ch); char c = (char) ch; - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c, "was expecting double-quote to start field name"); } // Also: note that although we use a different table here, it does NOT handle UTF-8 @@ -2248,7 +2221,6 @@ private JsonToken _handleOddName(int ch) throws IOException final int[] codes = CharTypes.getInputCodeUtf8JsNames(); // Also: must start with a valid character... if (codes[ch] != 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch, "was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name"); } @@ -2508,7 +2480,6 @@ private int _decodeSplitEscaped(int value, int bytesRead) throws IOException while (true) { int digit = CharTypes.charToHex(c); if (digit < 0) { - --_inputPtr; // for correct error reporting _reportUnexpectedChar(c & 0xFF, "expected a hex-digit for character escape sequence"); } value = (value << 4) | digit; @@ -2968,7 +2939,6 @@ private final int _decodeFastCharEscape() throws IOException } } } - --_inputPtr; // for correct error reporting _reportUnexpectedChar(ch & 0xFF, "expected a hex-digit for character escape sequence"); return -1; } diff --git a/src/test/java/com/fasterxml/jackson/failing/read/LocationOfError1173Test.java b/src/test/java/com/fasterxml/jackson/failing/read/LocationOfError1173Test.java index aea27cc9a6..43ef25ec7e 100644 --- a/src/test/java/com/fasterxml/jackson/failing/read/LocationOfError1173Test.java +++ b/src/test/java/com/fasterxml/jackson/failing/read/LocationOfError1173Test.java @@ -226,8 +226,8 @@ public JsonParser createParser(String input) throws Exception ), new InvalidJson( "Invalid JSON with raw unicode character", - // javac will parse the 3-byte unicode control sequence, it will be passed to the parser as a raw unicode character - a2q("{'validJson':'\u274c','right', 'here'}"), + // javac will parse the unicode control sequence, it will be passed to the parser as a raw unicode character + "{\"validJson\":\"\u274c\",\"right\", \"here\"}", 26, 24, 1,