Skip to content

Commit 7af6e97

Browse files
authored
use _updateToken (#504)
1 parent 6c32905 commit 7af6e97

File tree

6 files changed

+151
-172
lines changed

6 files changed

+151
-172
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/AvroParserImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ public String nextFieldName() throws IOException
108108
_binaryValue = null;
109109
String name = _avroContext.nextFieldName();
110110
if (name == null) {
111-
_currToken = _avroContext.getCurrentToken();
111+
_nullSafeUpdateToken(_avroContext.getCurrentToken());
112112
return null;
113113
}
114-
_currToken = JsonToken.FIELD_NAME;
114+
_updateToken(JsonToken.FIELD_NAME);
115115
return name;
116116
}
117117

@@ -124,10 +124,10 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
124124
_binaryValue = null;
125125
String name = _avroContext.nextFieldName();
126126
if (name == null) {
127-
_currToken = _avroContext.getCurrentToken();
127+
_nullSafeUpdateToken(_avroContext.getCurrentToken());
128128
return false;
129129
}
130-
_currToken = JsonToken.FIELD_NAME;
130+
_updateToken(JsonToken.FIELD_NAME);
131131
return name.equals(sstr.getValue());
132132
}
133133

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -791,16 +791,16 @@ public JsonToken nextToken() throws IOException
791791
if (!_streamReadContext.expectMoreValues()) {
792792
_stringRefs.pop();
793793
_streamReadContext = _streamReadContext.getParent();
794-
return (_currToken = JsonToken.END_OBJECT);
794+
return _updateToken(JsonToken.END_OBJECT);
795795
}
796-
return (_currToken = _decodePropertyName());
796+
return _updateToken(_decodePropertyName());
797797
}
798798
} else {
799799
if (!_streamReadContext.expectMoreValues()) {
800800
_stringRefs.pop();
801801
_tagValues.clear();
802802
_streamReadContext = _streamReadContext.getParent();
803-
return (_currToken = JsonToken.END_ARRAY);
803+
return _updateToken(JsonToken.END_ARRAY);
804804
}
805805
}
806806
if (_inputPtr >= _inputEnd) {
@@ -874,7 +874,7 @@ public JsonToken nextToken() throws IOException
874874
if (!_tagValues.isEmpty()) {
875875
return _handleTaggedInt(_tagValues);
876876
}
877-
return (_currToken = JsonToken.VALUE_NUMBER_INT);
877+
return _updateToken(JsonToken.VALUE_NUMBER_INT);
878878
case 1: // negative int
879879
_numTypesValid = NR_INT;
880880
if (lowBits <= 23) {
@@ -917,20 +917,20 @@ public JsonToken nextToken() throws IOException
917917
_invalidToken(ch);
918918
}
919919
}
920-
return (_currToken = JsonToken.VALUE_NUMBER_INT);
920+
return _updateToken(JsonToken.VALUE_NUMBER_INT);
921921

922922
case 2: // byte[]
923923
_typeByte = ch;
924924
_tokenIncomplete = true;
925925
if (!_tagValues.isEmpty()) {
926926
return _handleTaggedBinary(_tagValues);
927927
}
928-
return (_currToken = JsonToken.VALUE_EMBEDDED_OBJECT);
928+
return _updateToken(JsonToken.VALUE_EMBEDDED_OBJECT);
929929

930930
case 3: // String
931931
_typeByte = ch;
932932
_tokenIncomplete = true;
933-
return (_currToken = JsonToken.VALUE_STRING);
933+
return _updateToken(JsonToken.VALUE_STRING);
934934

935935
case 4: // Array
936936
_stringRefs.push(stringrefNamespace);
@@ -941,11 +941,11 @@ public JsonToken nextToken() throws IOException
941941
}
942942
createChildArrayContext(len);
943943
}
944-
return (_currToken = JsonToken.START_ARRAY);
944+
return _updateToken(JsonToken.START_ARRAY);
945945

946946
case 5: // Object
947947
_stringRefs.push(stringrefNamespace);
948-
_currToken = JsonToken.START_OBJECT;
948+
_updateToken(JsonToken.START_OBJECT);
949949
{
950950
int len = _decodeExplicitLength(lowBits);
951951
createChildObjectContext(len);
@@ -956,43 +956,43 @@ public JsonToken nextToken() throws IOException
956956
default: // misc: tokens, floats
957957
switch (lowBits) {
958958
case 20:
959-
return (_currToken = JsonToken.VALUE_FALSE);
959+
return _updateToken(JsonToken.VALUE_FALSE);
960960
case 21:
961-
return (_currToken = JsonToken.VALUE_TRUE);
961+
return _updateToken(JsonToken.VALUE_TRUE);
962962
case 22:
963-
return (_currToken = JsonToken.VALUE_NULL);
963+
return _updateToken(JsonToken.VALUE_NULL);
964964
case 23:
965-
return (_currToken = _decodeUndefinedValue());
965+
return _updateToken(_decodeUndefinedValue());
966966

967967
case 25: // 16-bit float...
968968
// As per [http://stackoverflow.com/questions/5678432/decompressing-half-precision-floats-in-javascript]
969969
{
970970
_numberFloat = (float) _decodeHalfSizeFloat();
971971
_numTypesValid = NR_FLOAT;
972972
}
973-
return (_currToken = JsonToken.VALUE_NUMBER_FLOAT);
973+
return _updateToken(JsonToken.VALUE_NUMBER_FLOAT);
974974
case 26: // Float32
975975
{
976976
_numberFloat = Float.intBitsToFloat(_decode32Bits());
977977
_numTypesValid = NR_FLOAT;
978978
}
979-
return (_currToken = JsonToken.VALUE_NUMBER_FLOAT);
979+
return _updateToken(JsonToken.VALUE_NUMBER_FLOAT);
980980
case 27: // Float64
981981
_numberDouble = Double.longBitsToDouble(_decode64Bits());
982982
_numTypesValid = NR_DOUBLE;
983-
return (_currToken = JsonToken.VALUE_NUMBER_FLOAT);
983+
return _updateToken(JsonToken.VALUE_NUMBER_FLOAT);
984984
case 31: // Break
985985
if (_streamReadContext.inArray()) {
986986
if (!_streamReadContext.hasExpectedLength()) {
987987
_stringRefs.pop();
988988
_streamReadContext = _streamReadContext.getParent();
989-
return (_currToken = JsonToken.END_ARRAY);
989+
return _updateToken(JsonToken.END_ARRAY);
990990
}
991991
}
992992
// Object end-marker can't occur here
993993
_reportUnexpectedBreak();
994994
}
995-
return (_currToken = _decodeSimpleValue(lowBits, ch));
995+
return _updateToken(_decodeSimpleValue(lowBits, ch));
996996
}
997997
}
998998

@@ -1072,7 +1072,7 @@ protected String _numberToName(int ch, boolean neg, TagList tags) throws IOExcep
10721072
protected JsonToken _handleTaggedInt(TagList tags) throws IOException {
10731073
// For now all we should get is stringref
10741074
if (!tags.contains(TAG_ID_STRINGREF)) {
1075-
return (_currToken = JsonToken.VALUE_NUMBER_INT);
1075+
return _updateToken(JsonToken.VALUE_NUMBER_INT);
10761076
}
10771077

10781078
if (_stringRefs.empty()) {
@@ -1090,7 +1090,7 @@ protected JsonToken _handleTaggedInt(TagList tags) throws IOException {
10901090
Object str = stringRefs.stringRefs.get(_numberInt);
10911091
if (str instanceof String) {
10921092
_sharedString = (String) str;
1093-
return (_currToken = JsonToken.VALUE_STRING);
1093+
return _updateToken(JsonToken.VALUE_STRING);
10941094
}
10951095
_binaryValue = (byte[]) str;
10961096
return _handleTaggedBinary(tags);
@@ -1110,7 +1110,7 @@ protected JsonToken _handleTaggedBinary(TagList tags) throws IOException
11101110
// 16-Jan-2024, tatu: Esoteric edge case where we have marked
11111111
// `int` as being tokenized
11121112
_numTypesValid = NR_UNKNOWN;
1113-
return (_currToken = JsonToken.VALUE_EMBEDDED_OBJECT);
1113+
return _updateToken(JsonToken.VALUE_EMBEDDED_OBJECT);
11141114
}
11151115

11161116
// First: get the data
@@ -1131,7 +1131,7 @@ protected JsonToken _handleTaggedBinary(TagList tags) throws IOException
11311131
}
11321132
_numTypesValid = NR_BIGINT;
11331133
_tagValues.clear();
1134-
return (_currToken = JsonToken.VALUE_NUMBER_INT);
1134+
return _updateToken(JsonToken.VALUE_NUMBER_INT);
11351135
}
11361136

11371137
protected JsonToken _handleTaggedArray(TagList tags, int len) throws IOException
@@ -1143,9 +1143,9 @@ protected JsonToken _handleTaggedArray(TagList tags, int len) throws IOException
11431143

11441144
// BigDecimal is the only thing we know for sure
11451145
if (!tags.contains(CBORConstants.TAG_DECIMAL_FRACTION)) {
1146-
return (_currToken = JsonToken.START_ARRAY);
1146+
return _updateToken(JsonToken.START_ARRAY);
11471147
}
1148-
_currToken = JsonToken.START_ARRAY;
1148+
_updateToken(JsonToken.START_ARRAY);
11491149

11501150
// but has to have length of 2; otherwise we have a problem...
11511151
if (len != 2) {
@@ -1181,7 +1181,7 @@ protected JsonToken _handleTaggedArray(TagList tags, int len) throws IOException
11811181
// which needs to be reset here
11821182
_numberBigDecimal = dec;
11831183
_numTypesValid = NR_BIGDECIMAL;
1184-
return (_currToken = JsonToken.VALUE_NUMBER_FLOAT);
1184+
return _updateToken(JsonToken.VALUE_NUMBER_FLOAT);
11851185
}
11861186

11871187
/**
@@ -1200,7 +1200,7 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
12001200
_tagValues.clear();
12011201
_stringRefs.pop();
12021202
_streamReadContext = _streamReadContext.getParent();
1203-
_currToken = JsonToken.END_ARRAY;
1203+
_updateToken(JsonToken.END_ARRAY);
12041204
return false;
12051205
}
12061206

@@ -1273,7 +1273,7 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
12731273
}
12741274
}
12751275
if (tagValues == null) {
1276-
_currToken = JsonToken.VALUE_NUMBER_INT;
1276+
_updateToken(JsonToken.VALUE_NUMBER_INT);
12771277
} else {
12781278
_handleTaggedInt(tagValues);
12791279
}
@@ -1320,7 +1320,7 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
13201320
_invalidToken(ch);
13211321
}
13221322
}
1323-
_currToken = JsonToken.VALUE_NUMBER_INT;
1323+
_updateToken(JsonToken.VALUE_NUMBER_INT);
13241324
return true;
13251325

13261326
case 2: // byte[]
@@ -1330,7 +1330,7 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
13301330
}
13311331
_typeByte = ch;
13321332
_tokenIncomplete = true;
1333-
_currToken = _handleTaggedBinary(tagValues);
1333+
_updateToken(_handleTaggedBinary(tagValues));
13341334
return (_currToken == JsonToken.VALUE_NUMBER_INT);
13351335
}
13361336

@@ -1348,7 +1348,7 @@ protected final boolean _checkNextIsEndArray() throws IOException
13481348
_tagValues.clear();
13491349
_stringRefs.pop();
13501350
_streamReadContext = _streamReadContext.getParent();
1351-
_currToken = JsonToken.END_ARRAY;
1351+
_updateToken(JsonToken.END_ARRAY);
13521352
return true;
13531353
}
13541354

@@ -1411,7 +1411,7 @@ public boolean nextFieldName(SerializableString str) throws IOException
14111411
if (!_streamReadContext.expectMoreValues()) {
14121412
_stringRefs.pop();
14131413
_streamReadContext = _streamReadContext.getParent();
1414-
_currToken = JsonToken.END_OBJECT;
1414+
_updateToken(JsonToken.END_OBJECT);
14151415
return false;
14161416
}
14171417
byte[] nameBytes = str.asQuotedUTF8();
@@ -1439,7 +1439,7 @@ public boolean nextFieldName(SerializableString str) throws IOException
14391439
_stringRefs.peek().stringRefs.add(strValue);
14401440
}
14411441
_streamReadContext.setCurrentName(strValue);
1442-
_currToken = JsonToken.FIELD_NAME;
1442+
_updateToken(JsonToken.FIELD_NAME);
14431443
return true;
14441444
}
14451445
if (nameBytes[i] != _inputBuffer[ptr + i]) {
@@ -1471,7 +1471,7 @@ public String nextFieldName() throws IOException
14711471
if (!_streamReadContext.expectMoreValues()) {
14721472
_stringRefs.pop();
14731473
_streamReadContext = _streamReadContext.getParent();
1474-
_currToken = JsonToken.END_OBJECT;
1474+
_updateToken(JsonToken.END_OBJECT);
14751475
return null;
14761476
}
14771477
// inlined "_decodeFieldName()"
@@ -1505,13 +1505,13 @@ public String nextFieldName() throws IOException
15051505
if (!_streamReadContext.hasExpectedLength()) {
15061506
_stringRefs.pop();
15071507
_streamReadContext = _streamReadContext.getParent();
1508-
_currToken = JsonToken.END_OBJECT;
1508+
_updateToken(JsonToken.END_OBJECT);
15091509
return null;
15101510
}
15111511
_reportUnexpectedBreak();
15121512
}
15131513
_decodeNonStringName(ch, _tagValues);
1514-
_currToken = JsonToken.FIELD_NAME;
1514+
_updateToken(JsonToken.FIELD_NAME);
15151515
return getText();
15161516
}
15171517
final int lenMarker = ch & 0x1F;
@@ -1552,7 +1552,7 @@ public String nextFieldName() throws IOException
15521552
_sharedString = name;
15531553
}
15541554
_streamReadContext.setCurrentName(name);
1555-
_currToken = JsonToken.FIELD_NAME;
1555+
_updateToken(JsonToken.FIELD_NAME);
15561556
return name;
15571557
}
15581558
// otherwise just fall back to default handling; should occur rarely

0 commit comments

Comments
 (0)