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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user