Skip to content

Commit 1aebcb3

Browse files
committed
Further improvements to error handling wrt Smile, number coercion
1 parent 4d587fc commit 1aebcb3

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParserBase.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -589,30 +589,30 @@ protected final void convertNumberToInt() throws IOException
589589
// Let's verify it's lossless conversion by simple roundtrip
590590
int result = (int) _numberLong;
591591
if (((long) result) != _numberLong) {
592-
_reportError("Numeric value (%s) out of range of int", getText());
592+
reportOverflowInt(String.valueOf(_numberLong));
593593
}
594594
_numberInt = result;
595595
} else if ((_numTypesValid & NR_BIGINT) != 0) {
596596
if (BI_MIN_INT.compareTo(_numberBigInt) > 0
597597
|| BI_MAX_INT.compareTo(_numberBigInt) < 0) {
598-
reportOverflowInt();
598+
reportOverflowInt(String.valueOf(_numberBigInt));
599599
}
600600
_numberInt = _numberBigInt.intValue();
601601
} else if ((_numTypesValid & NR_DOUBLE) != 0) {
602602
// Need to check boundaries
603603
if (_numberDouble < MIN_INT_D || _numberDouble > MAX_INT_D) {
604-
reportOverflowInt();
604+
reportOverflowInt(String.valueOf(_numberDouble));
605605
}
606606
_numberInt = (int) _numberDouble;
607607
} else if ((_numTypesValid & NR_FLOAT) != 0) {
608608
if (_numberFloat < MIN_INT_D || _numberFloat > MAX_INT_D) {
609-
reportOverflowInt();
609+
reportOverflowInt(String.valueOf(_numberFloat));
610610
}
611611
_numberInt = (int) _numberFloat;
612612
} else if ((_numTypesValid & NR_BIGDECIMAL) != 0) {
613613
if (BD_MIN_INT.compareTo(_numberBigDecimal) > 0
614614
|| BD_MAX_INT.compareTo(_numberBigDecimal) < 0) {
615-
reportOverflowInt();
615+
reportOverflowInt(String.valueOf(_numberBigDecimal));
616616
}
617617
_numberInt = _numberBigDecimal.intValue();
618618
} else {
@@ -629,23 +629,23 @@ protected final void convertNumberToLong() throws IOException
629629
} else if ((v & NR_BIGINT) != 0) {
630630
if (BI_MIN_LONG.compareTo(_numberBigInt) > 0
631631
|| BI_MAX_LONG.compareTo(_numberBigInt) < 0) {
632-
reportOverflowLong();
632+
reportOverflowLong(String.valueOf(_numberBigInt));
633633
}
634634
_numberLong = _numberBigInt.longValue();
635635
} else if ((v & NR_DOUBLE) != 0) {
636636
if (_numberDouble < MIN_LONG_D || _numberDouble > MAX_LONG_D) {
637-
reportOverflowLong();
637+
reportOverflowLong(String.valueOf(_numberDouble));
638638
}
639639
_numberLong = (long) _numberDouble;
640640
} else if ((v & NR_FLOAT) != 0) {
641641
if (_numberFloat < MIN_LONG_D || _numberFloat > MAX_LONG_D) {
642-
reportOverflowInt();
642+
reportOverflowLong(String.valueOf(_numberFloat));
643643
}
644644
_numberLong = (long) _numberFloat;
645645
} else if ((v & NR_BIGDECIMAL) != 0) {
646646
if (BD_MIN_LONG.compareTo(_numberBigDecimal) > 0
647647
|| BD_MAX_LONG.compareTo(_numberBigDecimal) < 0) {
648-
reportOverflowLong();
648+
reportOverflowLong(String.valueOf(_numberBigDecimal));
649649
}
650650
_numberLong = _numberBigDecimal.longValue();
651651
} else {

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/parse/NumberParsingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.math.BigInteger;
66

77
import com.fasterxml.jackson.core.*;
8+
import com.fasterxml.jackson.core.exc.InputCoercionException;
89
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
910
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
1011
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
@@ -485,7 +486,7 @@ public void testMixedAccessForInts() throws IOException
485486
try {
486487
p.getIntValue();
487488
fail("Should not pass");
488-
} catch (JsonParseException e) {
489+
} catch (InputCoercionException e) {
489490
verifyException(e, "Numeric value");
490491
verifyException(e, "out of range of int");
491492
}

0 commit comments

Comments
 (0)