diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index d3aa18870d..0a13082b4b 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -1195,8 +1195,14 @@ public class Util { */ @Nonnull public static String fixNull(@CheckForNull String s) { - if(s==null) return ""; - else return s; + return fixNull(s, ""); + } + + /** + * Convert null to defaultValue. + */ + public static T fixNull(@CheckForNull T s, T defaultValue) { + return s != null ? s : defaultValue; } /** @@ -1221,22 +1227,22 @@ public class Util { @Nonnull public static List fixNull(@CheckForNull List l) { - return l!=null ? l : Collections.emptyList(); + return fixNull(l, Collections.emptyList()); } @Nonnull public static Set fixNull(@CheckForNull Set l) { - return l!=null ? l : Collections.emptySet(); + return fixNull(l, Collections.emptySet()); } @Nonnull public static Collection fixNull(@CheckForNull Collection l) { - return l!=null ? l : Collections.emptySet(); + return fixNull(l, Collections.emptySet()); } @Nonnull public static Iterable fixNull(@CheckForNull Iterable l) { - return l!=null ? l : Collections.emptySet(); + return fixNull(l, Collections.emptySet()); } /**