Closed
Description
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:
- AbstractMessageSource does not properly interact with DelegatingMessageSource parent [SPR-16047] #20596 AbstractMessageSource does not properly interact with DelegatingMessageSource parent
- Introduce null-safety of Spring Framework API [SPR-15540] #20099 Introduce null-safety of Spring Framework API
Referenced from: commits e5c8dc0