@@ -652,9 +652,15 @@ protected final Float _parseFloat(JsonParser p, DeserializationContext ctxt)
652652 if (_checkTextualNull (ctxt , text )) {
653653 return (Float ) getNullValue (ctxt );
654654 }
655- try {
656- return NumberInput .parseFloat (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
657- } catch (IllegalArgumentException iae ) { }
655+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
656+ if (NumberInput .looksLikeValidNumber (text )) {
657+ p .streamReadConstraints ().validateFPLength (text .length ());
658+ try {
659+ return NumberInput .parseFloat (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
660+ } catch (IllegalArgumentException iae ) {
661+ if (true ) throw new Error ();
662+ }
663+ }
658664 return (Float ) ctxt .handleWeirdStringValue (_valueClass , text ,
659665 "not a valid `Float` value" );
660666 }
@@ -751,10 +757,13 @@ protected final Double _parseDouble(JsonParser p, DeserializationContext ctxt) t
751757 if (_checkTextualNull (ctxt , text )) {
752758 return (Double ) getNullValue (ctxt );
753759 }
754- p .streamReadConstraints ().validateFPLength (text .length ());
755- try {
756- return _parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
757- } catch (IllegalArgumentException iae ) { }
760+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
761+ if (NumberInput .looksLikeValidNumber (text )) {
762+ p .streamReadConstraints ().validateFPLength (text .length ());
763+ try {
764+ return _parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
765+ } catch (IllegalArgumentException iae ) { }
766+ }
758767 return (Double ) ctxt .handleWeirdStringValue (_valueClass , text ,
759768 "not a valid `Double` value" );
760769 }
@@ -843,30 +852,31 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
843852 return Double .NaN ;
844853 }
845854 try {
846- if (!_isIntNumber (text )) {
855+ if (_isIntNumber (text )) {
856+ p .streamReadConstraints ().validateIntegerLength (text .length ());
857+ if (ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
858+ return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
859+ }
860+ long value = NumberInput .parseLong (text );
861+ if (!ctxt .isEnabled (DeserializationFeature .USE_LONG_FOR_INTS )) {
862+ if (value <= Integer .MAX_VALUE && value >= Integer .MIN_VALUE ) {
863+ return Integer .valueOf ((int ) value );
864+ }
865+ }
866+ return value ;
867+ }
868+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
869+ if (NumberInput .looksLikeValidNumber (text )) {
847870 p .streamReadConstraints ().validateFPLength (text .length ());
848871 if (ctxt .isEnabled (DeserializationFeature .USE_BIG_DECIMAL_FOR_FLOATS )) {
849872 return NumberInput .parseBigDecimal (
850873 text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
851874 }
852- return Double .valueOf (
853- NumberInput .parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER )));
854- }
855- p .streamReadConstraints ().validateIntegerLength (text .length ());
856- if (ctxt .isEnabled (DeserializationFeature .USE_BIG_INTEGER_FOR_INTS )) {
857- return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
858- }
859- long value = NumberInput .parseLong (text );
860- if (!ctxt .isEnabled (DeserializationFeature .USE_LONG_FOR_INTS )) {
861- if (value <= Integer .MAX_VALUE && value >= Integer .MIN_VALUE ) {
862- return Integer .valueOf ((int ) value );
863- }
875+ return NumberInput .parseDouble (text , p .isEnabled (StreamReadFeature .USE_FAST_DOUBLE_PARSER ));
864876 }
865- return Long .valueOf (value );
866- } catch (IllegalArgumentException iae ) {
867- return ctxt .handleWeirdStringValue (_valueClass , text ,
868- "not a valid number" );
869- }
877+ } catch (IllegalArgumentException iae ) { }
878+ return ctxt .handleWeirdStringValue (_valueClass , text ,
879+ "not a valid number" );
870880 }
871881
872882 /**
@@ -966,10 +976,12 @@ public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws
966976 // note: no need to call `coerce` as this is never primitive
967977 return getNullValue (ctxt );
968978 }
969- p .streamReadConstraints ().validateIntegerLength (text .length ());
970- try {
971- return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
972- } catch (IllegalArgumentException iae ) { }
979+ if (_isIntNumber (text )) {
980+ p .streamReadConstraints ().validateIntegerLength (text .length ());
981+ try {
982+ return NumberInput .parseBigInteger (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
983+ } catch (IllegalArgumentException iae ) { }
984+ }
973985 return (BigInteger ) ctxt .handleWeirdStringValue (_valueClass , text ,
974986 "not a valid representation" );
975987 }
@@ -1036,10 +1048,13 @@ public BigDecimal deserialize(JsonParser p, DeserializationContext ctxt)
10361048 // note: no need to call `coerce` as this is never primitive
10371049 return getNullValue (ctxt );
10381050 }
1039- p .streamReadConstraints ().validateFPLength (text .length ());
1040- try {
1041- return NumberInput .parseBigDecimal (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
1042- } catch (IllegalArgumentException iae ) { }
1051+ // 09-Dec-2023, tatu: To avoid parser having to validate input, pre-validate:
1052+ if (NumberInput .looksLikeValidNumber (text )) {
1053+ p .streamReadConstraints ().validateFPLength (text .length ());
1054+ try {
1055+ return NumberInput .parseBigDecimal (text , p .isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
1056+ } catch (IllegalArgumentException iae ) { }
1057+ }
10431058 return (BigDecimal ) ctxt .handleWeirdStringValue (_valueClass , text ,
10441059 "not a valid representation" );
10451060 }
0 commit comments