Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 16, 2023
2 parents 50b55ff + 1aebcb3 commit fa0d443
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,30 +500,30 @@ protected final void convertNumberToInt() throws JacksonException
// Let's verify it's lossless conversion by simple roundtrip
int result = (int) _numberLong;
if (((long) result) != _numberLong) {
_reportError("Numeric value (%s) out of range of int", getText());
_reportOverflowInt(String.valueOf(_numberLong));
}
_numberInt = result;
} else if ((_numTypesValid & NR_BIGINT) != 0) {
if (BI_MIN_INT.compareTo(_numberBigInt) > 0
|| BI_MAX_INT.compareTo(_numberBigInt) < 0) {
_reportOverflowInt();
_reportOverflowInt(String.valueOf(_numberBigInt));
}
_numberInt = _numberBigInt.intValue();
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
// Need to check boundaries
if (_numberDouble < MIN_INT_D || _numberDouble > MAX_INT_D) {
_reportOverflowInt();
_reportOverflowInt(String.valueOf(_numberDouble));
}
_numberInt = (int) _numberDouble;
} else if ((_numTypesValid & NR_FLOAT) != 0) {
if (_numberFloat < MIN_INT_D || _numberFloat > MAX_INT_D) {
_reportOverflowInt();
_reportOverflowInt(String.valueOf(_numberFloat));
}
_numberInt = (int) _numberFloat;
} else if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
if (BD_MIN_INT.compareTo(_numberBigDecimal) > 0
|| BD_MAX_INT.compareTo(_numberBigDecimal) < 0) {
_reportOverflowInt();
_reportOverflowInt(String.valueOf(_numberBigDecimal));
}
_numberInt = _numberBigDecimal.intValue();
} else {
Expand All @@ -540,23 +540,23 @@ protected final void convertNumberToLong() throws JacksonException
} else if ((v & NR_BIGINT) != 0) {
if (BI_MIN_LONG.compareTo(_numberBigInt) > 0
|| BI_MAX_LONG.compareTo(_numberBigInt) < 0) {
_reportOverflowLong();
_reportOverflowLong(String.valueOf(_numberBigInt));
}
_numberLong = _numberBigInt.longValue();
} else if ((v & NR_DOUBLE) != 0) {
if (_numberDouble < MIN_LONG_D || _numberDouble > MAX_LONG_D) {
_reportOverflowLong();
_reportOverflowLong(String.valueOf(_numberDouble));
}
_numberLong = (long) _numberDouble;
} else if ((v & NR_FLOAT) != 0) {
if (_numberFloat < MIN_LONG_D || _numberFloat > MAX_LONG_D) {
_reportOverflowInt();
_reportOverflowLong(String.valueOf(_numberFloat));
}
_numberLong = (long) _numberFloat;
} else if ((v & NR_BIGDECIMAL) != 0) {
if (BD_MIN_LONG.compareTo(_numberBigDecimal) > 0
|| BD_MAX_LONG.compareTo(_numberBigDecimal) < 0) {
_reportOverflowLong();
_reportOverflowLong(String.valueOf(_numberBigDecimal));
}
_numberLong = _numberBigDecimal.longValue();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.math.BigInteger;

import tools.jackson.core.*;
import tools.jackson.core.exc.InputCoercionException;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.core.exc.StreamReadException;

Expand Down Expand Up @@ -489,7 +490,7 @@ public void testMixedAccessForInts() throws IOException
try {
p.getIntValue();
fail("Should not pass");
} catch (StreamReadException e) {
} catch (InputCoercionException e) {
verifyException(e, "Numeric value");
verifyException(e, "out of range of int");
}
Expand Down

0 comments on commit fa0d443

Please sign in to comment.