Skip to content

Commit

Permalink
Add _updateToken() calls to prep for #1310 (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Jun 16, 2024
1 parent 4a13a2f commit c65b70b
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.exc.InputCoercionException;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.core.io.JsonEOFException;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
Expand Down Expand Up @@ -818,6 +819,25 @@ protected final void _wrapError(String msg, Throwable t) throws JsonParseExcepti
throw _constructReadException(msg, t);
}

/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/

protected final JsonToken _updateToken(final JsonToken token) throws StreamConstraintsException {
_currToken = token;
return token;
}

protected final JsonToken _updateTokenToNull() {
return (_currToken = null);
}

protected final JsonToken _updateTokenToNA() {
return (_currToken = JsonToken.NOT_AVAILABLE);
}

@Deprecated // since 2.11
protected static byte[] _asciiBytes(String str) {
byte[] b = new byte[str.length()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public final JsonToken nextToken() throws IOException
// Should actually close/release things
// like input source, symbol table and recyclable buffers now.
close();
return (_currToken = null);
return _updateTokenToNull();
}
// clear any data retained so far
_binaryValue = null;
Expand Down Expand Up @@ -708,7 +708,7 @@ public final JsonToken nextToken() throws IOException
_updateNameLocation();
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
_parsingContext.setCurrentName(name);
_currToken = JsonToken.FIELD_NAME;
_updateToken(JsonToken.FIELD_NAME);
i = _skipColon();
}
_updateLocation();
Expand Down Expand Up @@ -785,8 +785,7 @@ public final JsonToken nextToken() throws IOException
_nextToken = t;
return _currToken;
}
_currToken = t;
return t;
return _updateToken(t);
}

private final JsonToken _nextAfterName() throws IOException
Expand All @@ -803,7 +802,7 @@ private final JsonToken _nextAfterName() throws IOException
} else if (t == JsonToken.START_OBJECT) {
createChildObjectContext(_tokenInputRow, _tokenInputCol);
}
return (_currToken = t);
return _updateToken(t);
}

@Override
Expand Down Expand Up @@ -837,7 +836,7 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
int i = _skipWSOrEnd();
if (i < 0) {
close();
_currToken = null;
_updateTokenToNull();
return false;
}
_binaryValue = null;
Expand Down Expand Up @@ -913,7 +912,7 @@ public String nextFieldName() throws IOException
int i = _skipWSOrEnd();
if (i < 0) {
close();
_currToken = null;
_updateTokenToNull();
return null;
}
_binaryValue = null;
Expand All @@ -939,7 +938,7 @@ public String nextFieldName() throws IOException
_updateNameLocation();
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
_parsingContext.setCurrentName(name);
_currToken = JsonToken.FIELD_NAME;
_updateToken(JsonToken.FIELD_NAME);
i = _skipColon();

_updateLocation();
Expand Down Expand Up @@ -1007,7 +1006,7 @@ public String nextFieldName() throws IOException

private final void _isNextTokenNameYes(int i) throws IOException
{
_currToken = JsonToken.FIELD_NAME;
_updateToken(JsonToken.FIELD_NAME);
_updateLocation();

switch (i) {
Expand Down Expand Up @@ -1067,7 +1066,7 @@ protected boolean _isNextTokenNameMaybe(int i, String nameToMatch) throws IOExce
// // // and this is back to standard nextToken()
String name = (i == INT_QUOTE) ? _parseName() : _handleOddName(i);
_parsingContext.setCurrentName(name);
_currToken = JsonToken.FIELD_NAME;
_updateToken(JsonToken.FIELD_NAME);
i = _skipColon();
_updateLocation();
if (i == INT_QUOTE) {
Expand Down Expand Up @@ -1133,32 +1132,32 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
{
if (i == INT_QUOTE) {
_tokenIncomplete = true;
return (_currToken = JsonToken.VALUE_STRING);
return _updateToken(JsonToken.VALUE_STRING);
}
switch (i) {
case '[':
createChildArrayContext(_tokenInputRow, _tokenInputCol);
return (_currToken = JsonToken.START_ARRAY);
return _updateToken(JsonToken.START_ARRAY);
case '{':
createChildObjectContext(_tokenInputRow, _tokenInputCol);
return (_currToken = JsonToken.START_OBJECT);
return _updateToken(JsonToken.START_OBJECT);
case 't':
_matchToken("true", 1);
return (_currToken = JsonToken.VALUE_TRUE);
return _updateToken(JsonToken.VALUE_TRUE);
case 'f':
_matchToken("false", 1);
return (_currToken = JsonToken.VALUE_FALSE);
return _updateToken(JsonToken.VALUE_FALSE);
case 'n':
_matchToken("null", 1);
return (_currToken = JsonToken.VALUE_NULL);
return _updateToken(JsonToken.VALUE_NULL);
case '-':
return (_currToken = _parseSignedNumber(true));
return _updateToken(_parseSignedNumber(true));
/* Should we have separate handling for plus? Although
* it is not allowed per se, it may be erroneously used,
* and could be indicated by a more specific error message.
*/
case '.': // [core#61]]
return (_currToken = _parseFloatThatStartsWithPeriod(false));
return _updateToken(_parseFloatThatStartsWithPeriod(false));
case '0':
case '1':
case '2':
Expand All @@ -1169,7 +1168,7 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
case '7':
case '8':
case '9':
return (_currToken = _parseUnsignedNumber(i));
return _updateToken(_parseUnsignedNumber(i));
/*
* This check proceeds only if the Feature.ALLOW_MISSING_VALUES is enabled
* The Check is for missing values. In case of missing values in an array, the next token will be either ',' or ']'.
Expand All @@ -1184,11 +1183,11 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
if (!_parsingContext.inRoot()) {
if ((_features & FEAT_MASK_ALLOW_MISSING) != 0) {
--_inputPtr;
return (_currToken = JsonToken.VALUE_NULL);
return _updateToken(JsonToken.VALUE_NULL);
}
}
}
return (_currToken = _handleOddValue(i));
return _updateToken(_handleOddValue(i));
}
// note: identical to one in UTF8StreamJsonParser
@Override
Expand All @@ -1198,7 +1197,7 @@ public final String nextTextValue() throws IOException
_nameCopied = false;
JsonToken t = _nextToken;
_nextToken = null;
_currToken = t;
_updateToken(t);
if (t == JsonToken.VALUE_STRING) {
if (_tokenIncomplete) {
_tokenIncomplete = false;
Expand All @@ -1225,7 +1224,7 @@ public final int nextIntValue(int defaultValue) throws IOException
_nameCopied = false;
JsonToken t = _nextToken;
_nextToken = null;
_currToken = t;
_updateToken(t);
if (t == JsonToken.VALUE_NUMBER_INT) {
return getIntValue();
}
Expand All @@ -1248,7 +1247,7 @@ public final long nextLongValue(long defaultValue) throws IOException
_nameCopied = false;
JsonToken t = _nextToken;
_nextToken = null;
_currToken = t;
_updateToken(t);
if (t == JsonToken.VALUE_NUMBER_INT) {
return getLongValue();
}
Expand All @@ -1271,7 +1270,7 @@ public final Boolean nextBooleanValue() throws IOException
_nameCopied = false;
JsonToken t = _nextToken;
_nextToken = null;
_currToken = t;
_updateToken(t);
if (t == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
}
Expand Down Expand Up @@ -3024,23 +3023,23 @@ protected void _reportInvalidToken(String matchedPart, String msg) throws IOExce
/**********************************************************
*/

private void _closeScope(int i) throws JsonParseException
private void _closeScope(int i) throws IOException
{
if (i == INT_RBRACKET) {
_updateLocation();
if (!_parsingContext.inArray()) {
_reportMismatchedEndMarker(i, '}');
}
_parsingContext = _parsingContext.clearAndGetParent();
_currToken = JsonToken.END_ARRAY;
_updateToken(JsonToken.END_ARRAY);
}
if (i == INT_RCURLY) {
_updateLocation();
if (!_parsingContext.inObject()) {
_reportMismatchedEndMarker(i, ']');
}
_parsingContext = _parsingContext.clearAndGetParent();
_currToken = JsonToken.END_OBJECT;
_updateToken(JsonToken.END_OBJECT);
}
}
}
Loading

0 comments on commit c65b70b

Please sign in to comment.