Skip to content

Commit f334d75

Browse files
authored
Final piece of refactoring wrt #668 (#1303)
1 parent 321b703 commit f334d75

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

src/main/java/tools/jackson/core/JacksonException.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public class JacksonException
1919
/**
2020
* Let's limit length of reference chain, to limit damage in cases
2121
* of infinite recursion.
22+
* Use maximum nesting limit allowed for reads.
2223
*/
23-
private final static int MAX_REFS_TO_LIST = 1000;
24+
private final static int MAX_REFS_TO_LIST = StreamReadConstraints.DEFAULT_MAX_DEPTH;
2425

2526
/**
2627
* Simple bean class used to contain references. References
@@ -483,24 +484,39 @@ public Object processor() {
483484
/**********************************************************************
484485
*/
485486

487+
@Override
488+
public String getLocalizedMessage() {
489+
return _buildMessage();
490+
}
491+
492+
/**
493+
* Method is overridden so that we can properly inject description
494+
* of problem path, if such is defined.
495+
*/
496+
@Override
497+
public String getMessage() {
498+
return _buildMessage();
499+
}
500+
486501
/**
487502
* Default method overridden so that we can add location information
488503
*
489504
* @return Message constructed based on possible optional prefix; explicit
490505
* {@code message} passed to constructor as well trailing location description
491506
* (separate from message by linefeed)
492507
*/
493-
@Override public String getMessage() {
494-
String msg = super.getMessage();
495-
if (msg == null) {
496-
msg = "N/A";
508+
protected String _buildMessage()
509+
{
510+
String baseMessage = super.getMessage();
511+
if (baseMessage == null) {
512+
baseMessage = "N/A";
497513
}
498514
JsonLocation loc = getLocation();
499515
String suffix = messageSuffix();
500516
// mild optimization, if nothing extra is needed:
517+
StringBuilder sb = new StringBuilder(200);
518+
sb.append(baseMessage);
501519
if ((loc != null) || suffix != null) {
502-
StringBuilder sb = new StringBuilder(100);
503-
sb.append(msg);
504520
if (suffix != null) {
505521
sb.append(suffix);
506522
}
@@ -509,12 +525,21 @@ public Object processor() {
509525
sb.append(" at ");
510526
sb = loc.toString(sb);
511527
}
512-
msg = sb.toString();
513528
}
514-
return msg;
529+
if (_path != null) {
530+
// 18-Feb-2009, tatu: originally there was a linefeed between
531+
// message and path reference; but unfortunately many systems
532+
// (loggers, junit) seem to assume linefeeds are only added to
533+
// separate stack trace.
534+
sb.append(" (through reference chain: ");
535+
sb = getPathReference(sb);
536+
sb.append(')');
537+
}
538+
return sb.toString();
515539
}
516540

517-
@Override public String toString() { return getClass().getName()+": "+getMessage(); }
541+
@Override
542+
public String toString() { return getClass().getName()+": "+getMessage(); }
518543

519544
/*
520545
/**********************************************************************

0 commit comments

Comments
 (0)