diff --git a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java index 26df79d7b711..bdd0f087b3ef 100644 --- a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,9 @@ package org.springframework.context.support; import java.text.MessageFormat; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -37,20 +39,20 @@ public class StaticMessageSource extends AbstractMessageSource { /** Map from 'code + locale' keys to message Strings. */ - private final Map messages = new HashMap<>(); + private final Map, String> messages = new HashMap<>(); - private final Map cachedMessageFormats = new HashMap<>(); + private final Map, MessageFormat> cachedMessageFormats = new HashMap<>(); @Override protected String resolveCodeWithoutArguments(String code, Locale locale) { - return this.messages.get(code + '_' + locale.toString()); + return this.messages.get(Arrays.asList(code, locale)); } @Override @Nullable protected MessageFormat resolveCode(String code, Locale locale) { - String key = code + '_' + locale.toString(); + List key = Arrays.asList(code, locale); String msg = this.messages.get(key); if (msg == null) { return null; @@ -75,7 +77,7 @@ public void addMessage(String code, Locale locale, String msg) { Assert.notNull(code, "Code must not be null"); Assert.notNull(locale, "Locale must not be null"); Assert.notNull(msg, "Message must not be null"); - this.messages.put(code + '_' + locale.toString(), msg); + this.messages.put(Arrays.asList(code, locale), msg); if (logger.isDebugEnabled()) { logger.debug("Added message [" + msg + "] for code [" + code + "] and Locale [" + locale + "]"); }