Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 27, 2025
2 parents ff6073c + 4bccb40 commit d54fabe
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 16 deletions.
6 changes: 6 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ a pure JSON library.
#1361: `JsonPointer` parsing of '~' not followed by "0" or "1" unexpected
(reported by @slz30)

2.18.3 (not yet released)

#1391: Fix issue where the parser can read back old number state when
parsing later numbers
(fix contributed by @pjfanning)

2.18.2 (27-Nov-2024)

#1359: Non-surrogate characters being incorrectly combined when
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tools/jackson/core/Base64Variants.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class Base64Variants
* This non-standard variant is usually used when encoded data needs to be
* passed via URLs (such as part of GET request). It differs from the
* base {@link #MIME} variant in multiple ways.
* First, no padding is used: this also means that it generally can not
* First, no padding is used: this also means that it generally cannot
* be written in multiple separate but adjacent chunks (which would not
* be the usual use case in any case). Also, no linefeeds are used (max
* line length set to infinite). And finally, two characters (plus and
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/core/JsonToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public enum JsonToken

/**
* NOT_AVAILABLE can be returned if {@link JsonParser}
* implementation can not currently return the requested
* implementation cannot currently return the requested
* token (usually next one), or even if any will be
* available, but that may be able to determine this in
* future. This is the case with non-blocking parsers --
* they can not block to wait for more data to parse and
* they cannot block to wait for more data to parse and
* must return something.
*/
NOT_AVAILABLE(null, JsonTokenId.ID_NOT_AVAILABLE),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tools/jackson/core/StreamReadFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public enum StreamReadFeature
* Most common reason for disabling this feature is to avoid leaking
* internal information; this may be done for security reasons.
* Note that even if source reference is included, only parts of contents are usually
* printed, and not the whole contents. Further, many source reference types can not
* printed, and not the whole contents. Further, many source reference types cannot
* necessarily access contents (like streams), so only type is indicated, not contents.
*<p>
* Feature is disabled by default for security reason (to avoid leaking additional source
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/tools/jackson/core/base/ParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ protected final JsonToken resetInt(boolean negative, int intLen)
_fractLength = 0;
_expLength = 0;
_numTypesValid = NR_UNKNOWN; // to force decoding
_numberString = null;
return JsonToken.VALUE_NUMBER_INT;
}

Expand All @@ -423,6 +424,7 @@ protected final JsonToken resetFloat(boolean negative, int intLen, int fractLen,
_fractLength = fractLen;
_expLength = expLen;
_numTypesValid = NR_UNKNOWN; // to force decoding
_numberString = null;
return JsonToken.VALUE_NUMBER_FLOAT;
}

Expand All @@ -432,6 +434,7 @@ protected final JsonToken resetAsNaN(String valueStr, double value)
_numberDouble = value;
_numTypesValid = NR_DOUBLE;
_numberIsNaN = true;
_numberString = null;
return JsonToken.VALUE_NUMBER_FLOAT;
}

Expand Down Expand Up @@ -630,6 +633,7 @@ public BigInteger getBigIntegerValue() throws JacksonException
}
if ((_numTypesValid & NR_BIGINT) == 0) {
convertNumberToBigInteger();
return _numberBigInt;
}
}
return _getBigInteger();
Expand All @@ -651,6 +655,7 @@ public float getFloatValue() throws JacksonException
}
if ((_numTypesValid & NR_FLOAT) == 0) {
convertNumberToFloat();
return _numberFloat;
}
}
return _getNumberFloat();
Expand All @@ -665,6 +670,7 @@ public double getDoubleValue() throws JacksonException
}
if ((_numTypesValid & NR_DOUBLE) == 0) {
convertNumberToDouble();
return _numberDouble;
}
}
return _getNumberDouble();
Expand All @@ -679,6 +685,7 @@ public BigDecimal getDecimalValue() throws JacksonException
}
if ((_numTypesValid & NR_BIGDECIMAL) == 0) {
convertNumberToBigDecimal();
return _numberBigDecimal;
}
}
return _getBigDecimal();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tools/jackson/core/io/IOContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class IOContext implements AutoCloseable
/**
* Reference temporary buffer Parser instances need if calling
* app decides it wants to access name via 'getTextCharacters' method.
* Regular text buffer can not be used as it may contain textual
* Regular text buffer cannot be used as it may contain textual
* representation of the value token.
*/
protected char[] _nameCopyBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private boolean checkUTF32(int quad) throws JacksonException
} else if ((quad & ~0x0000FF00) == 0) { // 0x0000??00 -> UTF32-in-order
_reportWeirdUCS4("2143");
} else {
// Can not be valid UTF-32 encoded JSON...
// Cannot be valid UTF-32 encoded JSON...
return false;
}
// Not BOM (just regular content), nothing to skip past:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/core/json/JsonWriteFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public enum JsonWriteFeature
* One use case is to avoid problems with Javascript limitations:
* since Javascript standard specifies that all number handling
* should be done using 64-bit IEEE 754 floating point values,
* result being that some 64-bit integer values can not be
* result being that some 64-bit integer values cannot be
* accurately represent (as mantissa is only 51 bit wide).
*<p>
* Feature is disabled by default.
Expand Down Expand Up @@ -119,7 +119,7 @@ public enum JsonWriteFeature
* <p>
* Note that this feature only has effect for {@link JsonGenerator}s that directly encode
* {@code byte}-based output, as UTF-8 (target {@link java.io.OutputStream}, {@code byte[]}
* and so on); it will not (can not) change handling of
* and so on); it will not (cannot) change handling of
* {@code char}-based output (like {@link java.io.Writer} or {@link java.lang.String}).
* <p>
* Feature is enabled by default in Jackson 3.0 (was disabled in 2.x).
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tools/jackson/core/json/UTF8JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ private final void _writeSegmentedRaw(char[] cbuf, int offset, int len) throws J
* Helper method that is called for segmented write of raw content
* when explicitly outputting a segment of longer thing.
* Caller has to take care of ensuring there's no split surrogate
* pair at the end (that is, last char can not be first part of a
* pair at the end (that is, last char cannot be first part of a
* surrogate char pair).
*/
private void _writeRawSegment(char[] cbuf, int offset, int end) throws JacksonException
Expand Down Expand Up @@ -1439,7 +1439,7 @@ private final void _writeStringSegments(String text, int offset, int totalLen) t
/**
* This method called when the string content is already in
* a char buffer, and its maximum total encoded and escaped length
* can not exceed size of the output buffer.
* cannot exceed size of the output buffer.
* Caller must ensure that there is enough space in output buffer,
* assuming case of all non-escaped ASCII characters, as well as
* potentially enough space for other cases (but not necessarily flushed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void endOfInput() {
// public long nextLongValue(long defaultValue) throws JacksonException
// public Boolean nextBooleanValue() throws JacksonException

// Should never be called: can not be implemented quite as expected
// Should never be called: cannot be implemented quite as expected
// due to non-blocking behavior
@Override
protected char _decodeEscaped() throws JacksonException {
Expand Down Expand Up @@ -759,7 +759,7 @@ private final JsonToken _startValueExpectColon(int ch) throws JacksonException
if (ch == INT_HASH) {
return _finishHashComment(MINOR_VALUE_EXPECTING_COLON);
}
// can not omit colon here
// cannot omit colon here
_reportUnexpectedChar(ch, "was expecting a colon to separate field name and value");
}
int ptr = _inputPtr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ private int _resizeAndFindOffsetForAdd(int hash) throws StreamConstraintsExcepti
// First things first: we need to resize+rehash (or, if too big, nuke contents)
rehash();

// Copy of main _findOffsetForAdd except for checks to resize: can not be needed
// Copy of main _findOffsetForAdd except for checks to resize: cannot be needed
int offset = _calcOffset(hash);
final int[] hashArea = _hashArea;
if (hashArea[offset+3] == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tools/jackson/core/util/Instantiatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Add-on interface used to indicate things that may be "blueprint" objects
* which can not be used as is, but are used for creating usable per-process
* which cannot be used as is, but are used for creating usable per-process
* (serialization, deserialization) instances, using
* {@link #createInstance} method.
*<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public int read(char[] b, int off, int len) throws IOException {

@Test
void simpleNumbers() throws Exception {
// DataInput can not detect EOF so:
// DataInput cannot detect EOF so:
_testSimpleNumbers(MODE_INPUT_STREAM);
_testSimpleNumbers(MODE_INPUT_STREAM_THROTTLED);
_testSimpleNumbers(MODE_READER);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package tools.jackson.core.unittest.read;

import java.math.BigDecimal;
import java.math.BigInteger;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JsonParser;
import tools.jackson.core.JsonToken;
import tools.jackson.core.TokenStreamFactory;

import tools.jackson.core.unittest.JacksonCoreTestBase;

import static org.junit.jupiter.api.Assertions.assertEquals;

class NumberParsingDb4917Test extends JacksonCoreTestBase
{
private TokenStreamFactory JSON_F = newStreamFactory();

final String INPUT_JSON = a2q("{'decimalHolder':100.00,'number':50}");

// [jackson-databind#4917]
@Test
public void bigDecimal4917Integers() throws Exception
{
for (int mode : ALL_MODES) {
testBigDecimal4917(JSON_F, mode, INPUT_JSON, true, JsonParser.NumberType.BIG_INTEGER);
testBigDecimal4917(JSON_F, mode, INPUT_JSON, true, JsonParser.NumberType.INT);
testBigDecimal4917(JSON_F, mode, INPUT_JSON, true, JsonParser.NumberType.LONG);
}
}

@Test
public void bigDecimal4917Floats() throws Exception
{
for (int mode : ALL_MODES) {
testBigDecimal4917(JSON_F, mode, INPUT_JSON, false, JsonParser.NumberType.DOUBLE);
testBigDecimal4917(JSON_F, mode, INPUT_JSON, true, JsonParser.NumberType.DOUBLE);
testBigDecimal4917(JSON_F, mode, INPUT_JSON, true, JsonParser.NumberType.FLOAT);
testBigDecimal4917(JSON_F, mode, INPUT_JSON, true, JsonParser.NumberType.BIG_DECIMAL);
}
}

private void testBigDecimal4917(final TokenStreamFactory jsonF,
final int mode,
final String json,
final boolean checkFirstNumValues,
final JsonParser.NumberType secondNumTypeCheck) throws Exception
{
// checkFirstNumValues=false reproduces the issue in https://github.com/FasterXML/jackson-databind/issues/4917
// it is useful to check the second number value while requesting different number types
// but the call adjusts state of the parser, so it is better to redo the test and then test w
try (JsonParser p = createParser(jsonF, mode, json)) {
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
assertEquals("decimalHolder", p.currentName());
assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(JsonParser.NumberType.DOUBLE, p.getNumberType());
if (checkFirstNumValues) {
assertEquals(Double.valueOf(100.0), p.getNumberValueDeferred());
assertEquals(new BigDecimal("100.00"), p.getDecimalValue());
}
assertEquals("100.00", p.getString());
assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
assertEquals("number", p.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(JsonParser.NumberType.INT, p.getNumberType());
assertEquals(Integer.valueOf(50), p.getNumberValueDeferred());
if (secondNumTypeCheck == JsonParser.NumberType.BIG_DECIMAL) {
assertEquals(new BigDecimal("50"), p.getDecimalValue());
} else if (secondNumTypeCheck == JsonParser.NumberType.BIG_INTEGER) {
assertEquals(new BigInteger("50"), p.getBigIntegerValue());
} else if (secondNumTypeCheck == JsonParser.NumberType.FLOAT) {
assertEquals(50.0f, p.getFloatValue());
} else if (secondNumTypeCheck == JsonParser.NumberType.LONG) {
assertEquals(50L, p.getLongValue());
} else if (secondNumTypeCheck == JsonParser.NumberType.INT) {
assertEquals(50, p.getIntValue());
} else {
assertEquals(50.0d, p.getDoubleValue());
}
assertEquals(50, p.getIntValue());
assertToken(JsonToken.END_OBJECT, p.nextToken());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void thousandsOfSymbolsWithChars() throws IOException
assertEquals(exp, symbolsCRoot.size());
}

// Note: can not validate root instance, is not set up same way
// Note: cannot validate root instance, is not set up same way
}

// Since 2.6
Expand Down

0 comments on commit d54fabe

Please sign in to comment.