Skip to content

Commit 940ebf4

Browse files
committed
Minor improvement to error handling wrt exception propagating via Creator (esp. for NPEs and other no-message exception types)
1 parent 644831c commit 940ebf4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -1589,15 +1589,21 @@ public JsonMappingException weirdNativeValueException(Object value, Class<?> ins
15891589
* to indicate problem with physically constructing instance of
15901590
* specified class (missing constructor, exception from constructor)
15911591
*<p>
1592-
* Note that most of the time this method should NOT be called; instead,
1592+
* Note that most of the time this method should NOT be called directly; instead,
15931593
* {@link #handleInstantiationProblem} should be called which will call this method
15941594
* if necessary.
15951595
*/
15961596
public JsonMappingException instantiationException(Class<?> instClass, Throwable cause) {
15971597
// Most likely problem with Creator definition, right?
1598-
JavaType type = constructType(instClass);
1598+
final JavaType type = constructType(instClass);
1599+
String excMsg;
1600+
if (cause == null) {
1601+
excMsg = "N/A";
1602+
} else if ((excMsg = cause.getMessage()) == null) {
1603+
excMsg = ClassUtil.nameOf(cause.getClass());
1604+
}
15991605
String msg = String.format("Cannot construct instance of %s, problem: %s",
1600-
ClassUtil.nameOf(instClass), cause.getMessage());
1606+
ClassUtil.nameOf(instClass), excMsg);
16011607
InvalidDefinitionException e = InvalidDefinitionException.from(_parser, msg, type);
16021608
e.initCause(cause);
16031609
return e;

0 commit comments

Comments
 (0)