Skip to content

Commit def56fe

Browse files
committed
implement and document fallback strategy
1 parent de3997a commit def56fe

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.cryptomator.integrations.common;
22

3+
import org.slf4j.LoggerFactory;
4+
5+
import java.util.MissingResourceException;
36
import java.util.ResourceBundle;
47

58
/**
@@ -11,15 +14,22 @@ public interface NamedServiceProvider {
1114
* Get the name of this service provider.
1215
*
1316
* @return The name of the service provider
14-
* @implNote The default implementation looks first for a {@link LocalizedDisplayName} and loads the name from the specified resource bundle/key. If the annotation is not present, the code looks for {@link DisplayName} and uses its value. If none of the former annotations are present, it falls back to the qualified class name.
17+
* @implNote The default implementation looks first for a {@link LocalizedDisplayName} and loads the name from the specified resource bundle/key. If the annotation is not present or loading the resource throws an exception, the code looks for {@link DisplayName} and uses its value. If none of the former annotations are present, it falls back to the qualified class name.
1518
* @see DisplayName
1619
* @see LocalizedDisplayName
1720
*/
1821
default String getName() {
1922
var localizedDisplayName = this.getClass().getAnnotation(LocalizedDisplayName.class);
2023
if (localizedDisplayName != null) {
21-
return ResourceBundle.getBundle(localizedDisplayName.bundle()) //
22-
.getString(localizedDisplayName.key());
24+
try {
25+
return ResourceBundle.getBundle(localizedDisplayName.bundle()) //
26+
.getString(localizedDisplayName.key());
27+
} catch (MissingResourceException e) {
28+
var clazz = this.getClass();
29+
var logger = LoggerFactory.getLogger(clazz);
30+
logger.warn("Failed to load localized display name for {}. Falling back to not-localized display name/class name.", clazz.getName());
31+
logger.debug("Reason for failure of {}.", clazz.getName(), e);
32+
}
2333
}
2434

2535
var displayName = this.getClass().getAnnotation(DisplayName.class);

0 commit comments

Comments
 (0)