Skip to content

Commit 26fd257

Browse files
committed
Merge branch '2.9' into 2.10
2 parents 39294f9 + f6cf181 commit 26fd257

19 files changed

+81
-36
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Project: jackson-databind
3434
- CVE-2018-14721)
3535
#2109: Canonical string for reference type is built incorrectly
3636
(reported by svarzee@github)
37+
#2128: Location information included twice for some `JsonMappingException`s
3738

3839
2.9.6 (12-Jun-2018)
3940

src/main/java/com/fasterxml/jackson/databind/DatabindContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ public JavaType resolveSubType(JavaType baseType, String subClass)
191191
} catch (Exception e) {
192192
throw invalidTypeIdException(baseType, subClass, String.format(
193193
"problem: (%s) %s",
194-
e.getClass().getName(), e.getMessage()));
194+
e.getClass().getName(),
195+
ClassUtil.exceptionMessage(e)));
195196
}
196197
if (baseType.isTypeOrSuperTypeOf(cls)) {
197198
return getTypeFactory().constructSpecializedType(baseType, cls);

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ public Date parseDate(String dateStr) throws IllegalArgumentException
711711
return df.parse(dateStr);
712712
} catch (ParseException e) {
713713
throw new IllegalArgumentException(String.format(
714-
"Failed to parse Date value '%s': %s", dateStr, e.getMessage()));
714+
"Failed to parse Date value '%s': %s", dateStr,
715+
ClassUtil.exceptionMessage(e)));
715716
}
716717
}
717718

@@ -1598,7 +1599,7 @@ public JsonMappingException instantiationException(Class<?> instClass, Throwable
15981599
String excMsg;
15991600
if (cause == null) {
16001601
excMsg = "N/A";
1601-
} else if ((excMsg = cause.getMessage()) == null) {
1602+
} else if ((excMsg = ClassUtil.exceptionMessage(cause)) == null) {
16021603
excMsg = ClassUtil.nameOf(cause.getClass());
16031604
}
16041605
String msg = String.format("Cannot construct instance of %s, problem: %s",

src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.fasterxml.jackson.annotation.JsonIgnore;
99
import com.fasterxml.jackson.core.*;
10+
import com.fasterxml.jackson.databind.util.ClassUtil;
1011

1112
/**
1213
* Checked exception used to signal fatal problems with mapping of
@@ -335,7 +336,8 @@ public static JsonMappingException from(SerializerProvider ctxt, String msg, Thr
335336
public static JsonMappingException fromUnexpectedIOE(IOException src) {
336337
return new JsonMappingException(null,
337338
String.format("Unexpected IOException (of type %s): %s",
338-
src.getClass().getName(), src.getMessage()));
339+
src.getClass().getName(),
340+
ClassUtil.exceptionMessage(src)));
339341
}
340342

341343
/**
@@ -375,7 +377,8 @@ public static JsonMappingException wrapWithPath(Throwable src, Reference ref)
375377
if (src instanceof JsonMappingException) {
376378
jme = (JsonMappingException) src;
377379
} else {
378-
String msg = src.getMessage();
380+
// [databind#2128]: try to avoid duplication
381+
String msg = ClassUtil.exceptionMessage(src);
379382
// Let's use a more meaningful placeholder if all we have is null
380383
if (msg == null || msg.length() == 0) {
381384
msg = "(was "+src.getClass().getName()+")";
@@ -486,9 +489,7 @@ public String getMessage() {
486489

487490
protected String _buildMessage()
488491
{
489-
/* First: if we have no path info, let's just use parent's
490-
* definition as is
491-
*/
492+
// First: if we have no path info, let's just use parent's definition as is
492493
String msg = super.getMessage();
493494
if (_path == null) {
494495
return msg;

src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,11 +1335,10 @@ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawTy
13351335
try {
13361336
ser = _createUntypedSerializer(fullType);
13371337
} catch (IllegalArgumentException iae) {
1338-
/* We better only expose checked exceptions, since those
1339-
* are what caller is expected to handle
1340-
*/
1338+
// We better only expose checked exceptions, since those
1339+
// are what caller is expected to handle
13411340
ser = null; // doesn't matter but compiler whines otherwise
1342-
reportMappingProblem(iae, iae.getMessage());
1341+
reportMappingProblem(iae, ClassUtil.exceptionMessage(iae));
13431342
}
13441343

13451344
if (ser != null) {
@@ -1359,7 +1358,7 @@ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type)
13591358
// We better only expose checked exceptions, since those
13601359
// are what caller is expected to handle
13611360
ser = null;
1362-
reportMappingProblem(iae, iae.getMessage());
1361+
reportMappingProblem(iae, ClassUtil.exceptionMessage(iae));
13631362
}
13641363

13651364
if (ser != null) {

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ public TypeDeserializer findTypeDeserializer(DeserializationConfig config,
15901590
return b.buildTypeDeserializer(config, baseType, subtypes);
15911591
} catch (IllegalArgumentException e0) {
15921592
InvalidDefinitionException e = InvalidDefinitionException.from((JsonParser) null,
1593-
e0.getMessage(), baseType);
1593+
ClassUtil.exceptionMessage(e0), baseType);
15941594
e.initCause(e0);
15951595
throw e;
15961596
}

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ public JsonDeserializer<Object> buildBeanDeserializer(DeserializationContext ctx
218218
// 05-Apr-2017, tatu: Although it might appear cleaner to require collector
219219
// to throw proper exception, it doesn't actually have reference to this
220220
// instance so...
221-
throw InvalidDefinitionException.from(ctxt.getParser(), e.getMessage(),
221+
throw InvalidDefinitionException.from(ctxt.getParser(),
222+
ClassUtil.exceptionMessage(e),
222223
beanDesc, null);
223224
}
224225
BeanDeserializerBuilder builder = constructBeanDeserializerBuilder(ctxt, beanDesc);
@@ -276,7 +277,8 @@ protected JsonDeserializer<Object> buildBuilderBasedDeserializer(
276277
// 05-Apr-2017, tatu: Although it might appear cleaner to require collector
277278
// to throw proper exception, it doesn't actually have reference to this
278279
// instance so...
279-
throw InvalidDefinitionException.from(ctxt.getParser(), e.getMessage(),
280+
throw InvalidDefinitionException.from(ctxt.getParser(),
281+
ClassUtil.exceptionMessage(e),
280282
builderDesc, null);
281283
}
282284
final DeserializationConfig config = ctxt.getConfig();

src/main/java/com/fasterxml/jackson/databind/deser/DeserializerCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ protected JsonDeserializer<Object> _createAndCache2(DeserializationContext ctxt,
265265
} catch (IllegalArgumentException iae) {
266266
// We better only expose checked exceptions, since those
267267
// are what caller is expected to handle
268-
throw JsonMappingException.from(ctxt, iae.getMessage(), iae);
268+
throw JsonMappingException.from(ctxt, ClassUtil.exceptionMessage(iae), iae);
269269
}
270270
if (deser == null) {
271271
return null;

src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected void _throwAsIOE(Exception e, Object propName, Object value)
199199
StringBuilder msg = new StringBuilder("Problem deserializing \"any\" property '").append(propName);
200200
msg.append("' of class "+getClassName()+" (expected type: ").append(_type);
201201
msg.append("; actual type: ").append(actType).append(")");
202-
String origMsg = e.getMessage();
202+
String origMsg = ClassUtil.exceptionMessage(e);
203203
if (origMsg != null) {
204204
msg.append(", problem: ").append(origMsg);
205205
} else {
@@ -211,7 +211,7 @@ protected void _throwAsIOE(Exception e, Object propName, Object value)
211211
ClassUtil.throwIfRTE(e);
212212
// let's wrap the innermost problem
213213
Throwable t = ClassUtil.getRootCause(e);
214-
throw new JsonMappingException(null, t.getMessage(), t);
214+
throw new JsonMappingException(null, ClassUtil.exceptionMessage(t), t);
215215
}
216216

217217
private String getClassName() { return _setter.getDeclaringClass().getName(); }

src/main/java/com/fasterxml/jackson/databind/deser/SettableBeanProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ protected void _throwAsIOE(JsonParser p, Exception e, Object value) throws IOExc
587587
.append(getType())
588588
.append("; actual type: ")
589589
.append(actType).append(")");
590-
String origMsg = e.getMessage();
590+
String origMsg = ClassUtil.exceptionMessage(e);
591591
if (origMsg != null) {
592592
msg.append(", problem: ")
593593
.append(origMsg);
@@ -608,7 +608,7 @@ protected IOException _throwAsIOE(JsonParser p, Exception e) throws IOException
608608
ClassUtil.throwIfRTE(e);
609609
// let's wrap the innermost problem
610610
Throwable th = ClassUtil.getRootCause(e);
611-
throw JsonMappingException.from(p, th.getMessage(), th);
611+
throw JsonMappingException.from(p, ClassUtil.exceptionMessage(th), th);
612612
}
613613

614614
@Deprecated // since 2.7

0 commit comments

Comments
 (0)