From 3af652833fcf622d5f78a958d9070e848fc1ae25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=A9=AC=E5=93=A5=EF=BC=88mercyblitz=EF=BC=89?= Date: Mon, 22 Apr 2024 11:55:08 +0800 Subject: [PATCH] Refactor --- .../i18n/AbstractResourceServiceMessageSource.java | 1 + .../i18n/PropertiesResourceServiceMessageSource.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/microsphere-i18n-core/src/main/java/io/microsphere/i18n/AbstractResourceServiceMessageSource.java b/microsphere-i18n-core/src/main/java/io/microsphere/i18n/AbstractResourceServiceMessageSource.java index 0b90187..beed2aa 100644 --- a/microsphere-i18n-core/src/main/java/io/microsphere/i18n/AbstractResourceServiceMessageSource.java +++ b/microsphere-i18n-core/src/main/java/io/microsphere/i18n/AbstractResourceServiceMessageSource.java @@ -141,6 +141,7 @@ protected String buildResourceName(Locale locale) { protected abstract String getResource(String resourceName); + @Nullable protected abstract Map loadMessages(String resource); @Nullable diff --git a/microsphere-i18n-core/src/main/java/io/microsphere/i18n/PropertiesResourceServiceMessageSource.java b/microsphere-i18n-core/src/main/java/io/microsphere/i18n/PropertiesResourceServiceMessageSource.java index 2566229..b382daf 100644 --- a/microsphere-i18n-core/src/main/java/io/microsphere/i18n/PropertiesResourceServiceMessageSource.java +++ b/microsphere-i18n-core/src/main/java/io/microsphere/i18n/PropertiesResourceServiceMessageSource.java @@ -11,7 +11,6 @@ import static io.microsphere.collection.CollectionUtils.isEmpty; import static io.microsphere.text.FormatUtils.format; -import static java.util.Collections.emptyMap; import static java.util.Collections.unmodifiableMap; /** @@ -28,7 +27,7 @@ public PropertiesResourceServiceMessageSource(String source) { @Override protected final Map loadMessages(String resource) { - Map messages = emptyMap(); + Map messages = null; try { Properties properties = loadAllProperties(resource); if (!MapUtils.isEmpty(properties)) { @@ -38,7 +37,7 @@ protected final Map loadMessages(String resource) { } catch (IOException e) { throw new RuntimeException(format("Source '{}' Messages Properties Resource[name : {}] loading is failed", source, resource), e); } - return unmodifiableMap(messages); + return messages == null ? null : unmodifiableMap(messages); } private Properties loadAllProperties(String resource) throws IOException {