This commit improves the fix for gh-18491 for Java 18 as in this case the exception message might not be null.