@@ -224,8 +224,10 @@ public int getMaxStringLength() {
224
224
public void validateNestingDepth (int depth ) throws StreamConstraintsException
225
225
{
226
226
if (depth > _maxNestingDepth ) {
227
- throw new StreamConstraintsException (String .format ("Depth (%d) exceeds the maximum allowed nesting depth (%d)" ,
228
- depth , _maxNestingDepth ));
227
+ throw _constructException (
228
+ "Document nesting depth (%d) exceeds the maximum allowed (%d, from %s)" ,
229
+ depth , _maxNestingDepth ,
230
+ _constrainRef ("getMaxNestingDepth" ));
229
231
}
230
232
}
231
233
@@ -249,8 +251,10 @@ public void validateNestingDepth(int depth) throws StreamConstraintsException
249
251
public void validateFPLength (int length ) throws StreamConstraintsException
250
252
{
251
253
if (length > _maxNumLen ) {
252
- throw new StreamConstraintsException (String .format ("Number length (%d) exceeds the maximum length (%d)" ,
253
- length , _maxNumLen ));
254
+ throw _constructException (
255
+ "Number value length (%d) exceeds the maximum allowed (%d, from %s)" ,
256
+ length , _maxNumLen ,
257
+ _constrainRef ("getMaxNumberLength" ));
254
258
}
255
259
}
256
260
@@ -268,8 +272,10 @@ public void validateFPLength(int length) throws StreamConstraintsException
268
272
public void validateIntegerLength (int length ) throws StreamConstraintsException
269
273
{
270
274
if (length > _maxNumLen ) {
271
- throw new StreamConstraintsException (String .format ("Number length (%d) exceeds the maximum length (%d)" ,
272
- length , _maxNumLen ));
275
+ throw _constructException (
276
+ "Number value length (%d) exceeds the maximum allowed (%d, from %s)" ,
277
+ length , _maxNumLen ,
278
+ _constrainRef ("getMaxNumberLength" ));
273
279
}
274
280
}
275
281
@@ -287,8 +293,10 @@ public void validateIntegerLength(int length) throws StreamConstraintsException
287
293
public void validateStringLength (int length ) throws StreamConstraintsException
288
294
{
289
295
if (length > _maxStringLen ) {
290
- throw new StreamConstraintsException (String .format ("String length (%d) exceeds the maximum length (%d)" ,
291
- length , _maxStringLen ));
296
+ throw _constructException (
297
+ "String value length (%d) exceeds the maximum allowed (%d, from %s)" ,
298
+ length , _maxStringLen ,
299
+ _constrainRef ("getMaxStringLength" ));
292
300
}
293
301
}
294
302
@@ -315,9 +323,23 @@ public void validateBigIntegerScale(int scale) throws StreamConstraintsException
315
323
final int limit = MAX_BIGINT_SCALE_MAGNITUDE ;
316
324
317
325
if (absScale > limit ) {
318
- throw new StreamConstraintsException ( String . format (
319
- "BigDecimal scale (%d) magnitude exceeds maximum allowed (%d)" ,
320
- scale , limit )) ;
326
+ throw _constructException (
327
+ "BigDecimal scale (%d) magnitude exceeds the maximum allowed (%d)" ,
328
+ scale , limit );
321
329
}
322
330
}
331
+
332
+ /*
333
+ /**********************************************************************
334
+ /* Error reporting
335
+ /**********************************************************************
336
+ */
337
+
338
+ protected StreamConstraintsException _constructException (String msgTemplate , Object ... args ) throws StreamConstraintsException {
339
+ throw new StreamConstraintsException (String .format (msgTemplate , args ));
340
+ }
341
+
342
+ protected String _constrainRef (String method ) {
343
+ return "`StreamReadConstraints." +method +"()`" ;
344
+ }
323
345
}
0 commit comments