Skip to content

Commit ac581be

Browse files
committed
Avoid NPE against null value from toString call
Closes gh-27782
1 parent 0802581 commit ac581be

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.commons.logging.Log;
2323

2424
import org.springframework.lang.Nullable;
25+
import org.springframework.util.ObjectUtils;
2526

2627
/**
2728
* Utility methods for formatting and logging messages.
@@ -71,10 +72,10 @@ public static String formatValue(
7172
}
7273
String result;
7374
try {
74-
result = value.toString();
75+
result = ObjectUtils.nullSafeToString(value);
7576
}
7677
catch (Throwable ex) {
77-
result = ex.toString();
78+
result = ObjectUtils.nullSafeToString(ex);
7879
}
7980
if (maxLength != -1) {
8081
result = (result.length() > maxLength ? result.substring(0, maxLength) + " (truncated)..." : result);

0 commit comments

Comments
 (0)