Browse Source

Fix ClassCastException message detection on Java 11

This commit also fixes the detection of a ClassCastException that can
be safely ignored on the module path with Java 9

Closes gh-14033
pull/14043/head
Stephane Nicoll 8 years ago
parent
commit
0ca8f1083a
  1. 13
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/LambdaSafe.java

13
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/LambdaSafe.java

@ -188,9 +188,22 @@ public final class LambdaSafe { @@ -188,9 +188,22 @@ public final class LambdaSafe {
return false;
}
Class<? extends Object> argumentType = argument.getClass();
// On Java 8, the message starts with the class name: "java.lang.String cannot
// be cast..."
if (message.startsWith(argumentType.getName())) {
return true;
}
// On Java 11, the message starts with "class ..." a.k.a. Class.toString()
if (message.startsWith(argumentType.toString())) {
return true;
}
// On Java 9, the message used to contain the module name:
// "java.base/java.lang.String cannot be cast..."
int moduleSeparatorIndex = message.indexOf('/');
if (moduleSeparatorIndex != -1 && message.startsWith(argumentType.getName(),
moduleSeparatorIndex + 1)) {
return true;
}
if (CLASS_GET_MODULE != null) {
Object module = ReflectionUtils.invokeMethod(CLASS_GET_MODULE,
argumentType);

Loading…
Cancel
Save