Avoid NPE against null value from toString call

Closes gh-27782
This commit is contained in:
Juergen Hoeller 2021-12-14 16:46:42 +01:00
parent 0802581aff
commit ac581bed92
1 changed files with 3 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
* Utility methods for formatting and logging messages.
@ -71,10 +72,10 @@ public abstract class LogFormatUtils {
}
String result;
try {
result = value.toString();
result = ObjectUtils.nullSafeToString(value);
}
catch (Throwable ex) {
result = ex.toString();
result = ObjectUtils.nullSafeToString(ex);
}
if (maxLength != -1) {
result = (result.length() > maxLength ? result.substring(0, maxLength) + " (truncated)..." : result);