diff --git a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java index 18dffe1f0376..669be70566e5 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ReloadableResourceBundleMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -25,7 +25,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -431,7 +430,7 @@ protected PropertiesHolder refreshProperties(String filename, @Nullable Properti long refreshTimestamp = (getCacheMillis() < 0 ? -1 : System.currentTimeMillis()); Resource resource = resolveResource(filename); - if (resource.exists()) { + if (resource != null) { long fileTimestamp = -1; if (getCacheMillis() >= 0) { // Last-modified timestamp of file will just be read if caching with timeout. @@ -508,18 +507,18 @@ protected PropertiesHolder refreshProperties(String filename, @Nullable Properti * {@link PropertiesPersister#load(Properties, InputStream) load} methods * for other types of resources. * @param filename the bundle filename (basename + Locale) - * @return the {@code Resource} to use + * @return the {@code Resource} to use, or {@code null} if none found * @since 6.1 */ + @Nullable protected Resource resolveResource(String filename) { - Resource resource = null; for (String fileExtension : this.fileExtensions) { - resource = this.resourceLoader.getResource(filename + fileExtension); + Resource resource = this.resourceLoader.getResource(filename + fileExtension); if (resource.exists()) { return resource; } } - return Objects.requireNonNull(resource); + return null; } /** diff --git a/spring-context/src/test/java/org/springframework/context/support/ResourceBundleMessageSourceTests.java b/spring-context/src/test/java/org/springframework/context/support/ResourceBundleMessageSourceTests.java index 514356b3bbfd..1ade17189d9e 100644 --- a/spring-context/src/test/java/org/springframework/context/support/ResourceBundleMessageSourceTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/ResourceBundleMessageSourceTests.java @@ -126,8 +126,7 @@ protected void doTestMessageAccess( if (alwaysUseMessageFormat) { pvs.add("alwaysUseMessageFormat", Boolean.TRUE); } - Class clazz = reloadable ? - (Class) ReloadableResourceBundleMessageSource.class : ResourceBundleMessageSource.class; + Class clazz = reloadable ? ReloadableResourceBundleMessageSource.class : ResourceBundleMessageSource.class; ac.registerSingleton("messageSource", clazz, pvs); ac.refresh();