Skip to content

Commit

Permalink
Avoid NPE against null value from toString call
Browse files Browse the repository at this point in the history
Closes gh-27782
  • Loading branch information
jhoeller committed Dec 14, 2021
1 parent 354dad6 commit 67a4b63
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;

import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;

/**
* Utility methods for formatting and logging messages.
Expand Down Expand Up @@ -71,10 +72,10 @@ public static String formatValue(
}
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);
Expand Down

0 comments on commit 67a4b63

Please sign in to comment.