Make MessageSource locale parameter nullable
Backport Bot / build (push) Has been cancelled
Details
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Has been cancelled
Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:false version:17], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled
Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:21], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled
Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:23], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled
Details
Deploy Docs / Dispatch docs deployment (push) Has been cancelled
Details
Build and Deploy Snapshot / Verify (push) Has been cancelled
Details
Backport Bot / build (push) Has been cancelled
Details
Build and Deploy Snapshot / Build and Deploy Snapshot (push) Has been cancelled
Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:false version:17], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled
Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:21], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled
Details
CI / ${{ matrix.os.name}} | Java ${{ matrix.java.version}} (map[toolchain:true version:23], map[id:ubuntu-latest name:Linux]) (push) Has been cancelled
Details
Deploy Docs / Dispatch docs deployment (push) Has been cancelled
Details
Build and Deploy Snapshot / Verify (push) Has been cancelled
Details
Closes gh-35230
This commit is contained in:
parent
445da24631
commit
5e338ef1b8
|
@ -55,7 +55,7 @@ public interface MessageSource {
|
||||||
* @see java.text.MessageFormat
|
* @see java.text.MessageFormat
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale);
|
String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, @Nullable Locale locale);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to resolve the message. Treat as an error if the message can't be found.
|
* Try to resolve the message. Treat as an error if the message can't be found.
|
||||||
|
@ -71,7 +71,7 @@ public interface MessageSource {
|
||||||
* @see #getMessage(MessageSourceResolvable, Locale)
|
* @see #getMessage(MessageSourceResolvable, Locale)
|
||||||
* @see java.text.MessageFormat
|
* @see java.text.MessageFormat
|
||||||
*/
|
*/
|
||||||
String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException;
|
String getMessage(String code, @Nullable Object[] args, @Nullable Locale locale) throws NoSuchMessageException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to resolve the message using all the attributes contained within the
|
* Try to resolve the message using all the attributes contained within the
|
||||||
|
@ -91,6 +91,6 @@ public interface MessageSource {
|
||||||
* @see MessageSourceResolvable#getDefaultMessage()
|
* @see MessageSourceResolvable#getDefaultMessage()
|
||||||
* @see java.text.MessageFormat
|
* @see java.text.MessageFormat
|
||||||
*/
|
*/
|
||||||
String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException;
|
String getMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) throws NoSuchMessageException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1502,17 +1502,17 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
|
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, @Nullable Locale locale) {
|
||||||
return getMessageSource().getMessage(code, args, defaultMessage, locale);
|
return getMessageSource().getMessage(code, args, defaultMessage, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException {
|
public String getMessage(String code, @Nullable Object[] args, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
return getMessageSource().getMessage(code, args, locale);
|
return getMessageSource().getMessage(code, args, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
|
public String getMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
return getMessageSource().getMessage(resolvable, locale);
|
return getMessageSource().getMessage(resolvable, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public final String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
|
public final String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, @Nullable Locale locale) {
|
||||||
String msg = getMessageInternal(code, args, locale);
|
String msg = getMessageInternal(code, args, locale);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -150,7 +150,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException {
|
public final String getMessage(String code, @Nullable Object[] args, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
String msg = getMessageInternal(code, args, locale);
|
String msg = getMessageInternal(code, args, locale);
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -159,11 +159,16 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
|
||||||
if (fallback != null) {
|
if (fallback != null) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
if (locale == null ) {
|
||||||
|
throw new NoSuchMessageException(code);
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new NoSuchMessageException(code, locale);
|
throw new NoSuchMessageException(code, locale);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
|
public final String getMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
String[] codes = resolvable.getCodes();
|
String[] codes = resolvable.getCodes();
|
||||||
if (codes != null) {
|
if (codes != null) {
|
||||||
for (String code : codes) {
|
for (String code : codes) {
|
||||||
|
@ -177,7 +182,13 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
|
||||||
if (defaultMessage != null) {
|
if (defaultMessage != null) {
|
||||||
return defaultMessage;
|
return defaultMessage;
|
||||||
}
|
}
|
||||||
throw new NoSuchMessageException(!ObjectUtils.isEmpty(codes) ? codes[codes.length - 1] : "", locale);
|
String code = !ObjectUtils.isEmpty(codes) ? codes[codes.length - 1] : "";
|
||||||
|
if (locale == null ) {
|
||||||
|
throw new NoSuchMessageException(code);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new NoSuchMessageException(code, locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +295,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
|
||||||
* @see #getDefaultMessage(String)
|
* @see #getDefaultMessage(String)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) {
|
protected String getDefaultMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) {
|
||||||
String defaultMessage = resolvable.getDefaultMessage();
|
String defaultMessage = resolvable.getDefaultMessage();
|
||||||
String[] codes = resolvable.getCodes();
|
String[] codes = resolvable.getCodes();
|
||||||
if (defaultMessage != null) {
|
if (defaultMessage != null) {
|
||||||
|
@ -331,7 +342,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
|
||||||
* @return an array of arguments with any MessageSourceResolvables resolved
|
* @return an array of arguments with any MessageSourceResolvables resolved
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Object[] resolveArguments(@Nullable Object[] args, Locale locale) {
|
protected Object[] resolveArguments(@Nullable Object[] args, @Nullable Locale locale) {
|
||||||
if (ObjectUtils.isEmpty(args)) {
|
if (ObjectUtils.isEmpty(args)) {
|
||||||
return super.resolveArguments(args, locale);
|
return super.resolveArguments(args, locale);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class DelegatingMessageSource extends MessageSourceSupport implements Hie
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
|
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, @Nullable Locale locale) {
|
||||||
if (this.parentMessageSource != null) {
|
if (this.parentMessageSource != null) {
|
||||||
return this.parentMessageSource.getMessage(code, args, defaultMessage, locale);
|
return this.parentMessageSource.getMessage(code, args, defaultMessage, locale);
|
||||||
}
|
}
|
||||||
|
@ -68,17 +68,22 @@ public class DelegatingMessageSource extends MessageSourceSupport implements Hie
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException {
|
public String getMessage(String code, @Nullable Object[] args, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
if (this.parentMessageSource != null) {
|
if (this.parentMessageSource != null) {
|
||||||
return this.parentMessageSource.getMessage(code, args, locale);
|
return this.parentMessageSource.getMessage(code, args, locale);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (locale == null) {
|
||||||
|
throw new NoSuchMessageException(code);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new NoSuchMessageException(code, locale);
|
throw new NoSuchMessageException(code, locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
|
public String getMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
if (this.parentMessageSource != null) {
|
if (this.parentMessageSource != null) {
|
||||||
return this.parentMessageSource.getMessage(resolvable, locale);
|
return this.parentMessageSource.getMessage(resolvable, locale);
|
||||||
}
|
}
|
||||||
|
@ -88,9 +93,14 @@ public class DelegatingMessageSource extends MessageSourceSupport implements Hie
|
||||||
}
|
}
|
||||||
String[] codes = resolvable.getCodes();
|
String[] codes = resolvable.getCodes();
|
||||||
String code = (codes != null && codes.length > 0 ? codes[0] : "");
|
String code = (codes != null && codes.length > 0 ? codes[0] : "");
|
||||||
|
if (locale == null) {
|
||||||
|
throw new NoSuchMessageException(code);
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new NoSuchMessageException(code, locale);
|
throw new NoSuchMessageException(code, locale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -98,7 +98,7 @@ public abstract class MessageSourceSupport {
|
||||||
* @return the rendered default message (with resolved arguments)
|
* @return the rendered default message (with resolved arguments)
|
||||||
* @see #formatMessage(String, Object[], java.util.Locale)
|
* @see #formatMessage(String, Object[], java.util.Locale)
|
||||||
*/
|
*/
|
||||||
protected String renderDefaultMessage(String defaultMessage, @Nullable Object[] args, Locale locale) {
|
protected String renderDefaultMessage(String defaultMessage, @Nullable Object[] args, @Nullable Locale locale) {
|
||||||
return formatMessage(defaultMessage, args, locale);
|
return formatMessage(defaultMessage, args, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public abstract class MessageSourceSupport {
|
||||||
* @param locale the Locale used for formatting
|
* @param locale the Locale used for formatting
|
||||||
* @return the formatted message (with resolved arguments)
|
* @return the formatted message (with resolved arguments)
|
||||||
*/
|
*/
|
||||||
protected String formatMessage(String msg, @Nullable Object[] args, Locale locale) {
|
protected String formatMessage(String msg, @Nullable Object[] args, @Nullable Locale locale) {
|
||||||
if (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args)) {
|
if (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args)) {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ public abstract class MessageSourceSupport {
|
||||||
* @param locale the Locale to create a {@code MessageFormat} for
|
* @param locale the Locale to create a {@code MessageFormat} for
|
||||||
* @return the {@code MessageFormat} instance
|
* @return the {@code MessageFormat} instance
|
||||||
*/
|
*/
|
||||||
protected MessageFormat createMessageFormat(String msg, Locale locale) {
|
protected MessageFormat createMessageFormat(String msg, @Nullable Locale locale) {
|
||||||
return new MessageFormat(msg, locale);
|
return new MessageFormat(msg, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ public abstract class MessageSourceSupport {
|
||||||
* @param locale the Locale to resolve against
|
* @param locale the Locale to resolve against
|
||||||
* @return the resolved argument array
|
* @return the resolved argument array
|
||||||
*/
|
*/
|
||||||
protected Object[] resolveArguments(@Nullable Object[] args, Locale locale) {
|
protected Object[] resolveArguments(@Nullable Object[] args, @Nullable Locale locale) {
|
||||||
return (args != null ? args : new Object[0]);
|
return (args != null ? args : new Object[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -357,17 +357,17 @@ class StubWebApplicationContext implements WebApplicationContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
|
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, @Nullable Locale locale) {
|
||||||
return this.messageSource.getMessage(code, args, defaultMessage, locale);
|
return this.messageSource.getMessage(code, args, defaultMessage, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException {
|
public String getMessage(String code, @Nullable Object[] args, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
return this.messageSource.getMessage(code, args, locale);
|
return this.messageSource.getMessage(code, args, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
|
public String getMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) throws NoSuchMessageException {
|
||||||
return this.messageSource.getMessage(resolvable, locale);
|
return this.messageSource.getMessage(resolvable, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ public abstract class BindErrorUtils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) {
|
protected String getDefaultMessage(MessageSourceResolvable resolvable, @Nullable Locale locale) {
|
||||||
String message = super.getDefaultMessage(resolvable, locale);
|
String message = super.getDefaultMessage(resolvable, locale);
|
||||||
return (resolvable instanceof FieldError error ? error.getField() + ": " + message : message);
|
return (resolvable instanceof FieldError error ? error.getField() + ": " + message : message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue