@@ -63,7 +63,7 @@ public static BigDecimal parse(final char[] chars, final int off, final int len)
63
63
// 20-Aug-2022, tatu: Although "new BigDecimal(...)" only throws NumberFormatException
64
64
// operations by "parseBigDecimal()" can throw "ArithmeticException", so handle both:
65
65
} catch (ArithmeticException | NumberFormatException e ) {
66
- throw _parseFailure (e , new String ( chars , off , len ) );
66
+ throw _parseFailure (e , chars , off , len );
67
67
}
68
68
}
69
69
@@ -115,7 +115,7 @@ public static BigDecimal parseWithFastParser(final char[] ch, final int off, fin
115
115
try {
116
116
return JavaBigDecimalParser .parseBigDecimal (ch , off , len );
117
117
} catch (ArithmeticException | NumberFormatException e ) {
118
- throw _parseFailure (e , new String ( ch , off , len ) );
118
+ throw _parseFailure (e , ch , off , len );
119
119
}
120
120
}
121
121
@@ -126,18 +126,43 @@ private static NumberFormatException _parseFailure(Exception e, String fullValue
126
126
desc = "Not a valid number representation" ;
127
127
}
128
128
String valueToReport = _getValueDesc (fullValue );
129
- return new NumberFormatException ("Value " + valueToReport
130
- + " can not be deserialized as `java.math.BigDecimal`, reason: " + desc );
129
+ return new NumberFormatException (_generateExceptionMessage (valueToReport , desc ));
131
130
}
132
131
133
- private static String _getValueDesc (String fullValue ) {
132
+ private static NumberFormatException _parseFailure (final Exception e ,
133
+ final char [] array ,
134
+ final int offset ,
135
+ final int len ) {
136
+ String desc = e .getMessage ();
137
+ // 05-Feb-2021, tatu: Alas, JDK mostly has null message so:
138
+ if (desc == null ) {
139
+ desc = "Not a valid number representation" ;
140
+ }
141
+ String valueToReport = _getValueDesc (array , offset , len );
142
+ return new NumberFormatException (_generateExceptionMessage (valueToReport , desc ));
143
+ }
144
+
145
+ private static String _getValueDesc (final String fullValue ) {
134
146
final int len = fullValue .length ();
135
147
if (len <= MAX_CHARS_TO_REPORT ) {
136
148
return String .format ("\" %s\" " , fullValue );
137
149
}
138
150
return String .format ("\" %s\" (truncated to %d chars (from %d))" ,
139
- fullValue .substring (0 , MAX_CHARS_TO_REPORT ),
140
- MAX_CHARS_TO_REPORT , len );
151
+ fullValue .substring (0 , MAX_CHARS_TO_REPORT ),
152
+ MAX_CHARS_TO_REPORT , len );
141
153
}
142
154
155
+ private static String _getValueDesc (final char [] array , final int offset , final int len ) {
156
+ if (len <= MAX_CHARS_TO_REPORT ) {
157
+ return String .format ("\" %s\" " , new String (array , offset , len ));
158
+ }
159
+ return String .format ("\" %s\" (truncated to %d chars (from %d))" ,
160
+ new String (array , offset , MAX_CHARS_TO_REPORT ),
161
+ MAX_CHARS_TO_REPORT , len );
162
+ }
163
+
164
+ private static String _generateExceptionMessage (final String valueToReport , final String desc ) {
165
+ return String .format ("Value %s can not be deserialized as `java.math.BigDecimal`, reason: %s" ,
166
+ valueToReport , desc );
167
+ }
143
168
}
0 commit comments