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