Thomas Heigl opened SPR-16127 and commented
I just encountered some issues in my application due to a subtle change in AbstractMessageSource between Spring 4.x and 5.x.
In Spring 4.x is was possible to pass null as defaultMessage, Spring 5.x always returns an empty string.
Spring 4.x:
public final String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
String msg = getMessageInternal(code, args, locale);
if (msg != null) {
return msg;
}
if (defaultMessage == null) {
String fallback = getDefaultMessage(code);
if (fallback != null) {
return fallback;
}
}
return renderDefaultMessage(defaultMessage, args, locale);
}
Spring 5.x:
public final String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
String msg = getMessageInternal(code, args, locale);
if (msg != null) {
return msg;
}
if (defaultMessage == null) {
String fallback = getDefaultMessage(code);
return (fallback != null ? fallback : "");
}
return renderDefaultMessage(defaultMessage, args, locale);
}
If the default message is null and the fallback is null Spring now returns "".
This makes it hard to distinguish between properties that are defined but empty and properties that are undefined.
Affects: 5.0.1
Issue Links:
Referenced from: commits e5c8dc0
Thomas Heigl opened SPR-16127 and commented
I just encountered some issues in my application due to a subtle change in
AbstractMessageSourcebetween Spring 4.x and 5.x.In Spring 4.x is was possible to pass
nullasdefaultMessage, Spring 5.x always returns an empty string.Spring 4.x:
Spring 5.x:
If the default message is
nulland the fallback isnullSpring now returns"".This makes it hard to distinguish between properties that are defined but empty and properties that are undefined.
Affects: 5.0.1
Issue Links:
Referenced from: commits e5c8dc0