From 278f59c11a6a19c34a9ff23a450ada3f775f5e75 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 21 Nov 2017 18:03:57 +0100 Subject: [PATCH] [Fix] I18nMessage.handle missing property and empty value in I18nMessage --- .../main/java/li/strolch/utils/I18nMessage.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/I18nMessage.java b/li.strolch.utils/src/main/java/li/strolch/utils/I18nMessage.java index b0c3226ef..3f0cdf93a 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/I18nMessage.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/I18nMessage.java @@ -2,14 +2,19 @@ package li.strolch.utils; import static li.strolch.utils.helper.StringHelper.EMPTY; +import java.util.MissingResourceException; import java.util.Properties; import java.util.ResourceBundle; import li.strolch.utils.dbc.DBC; import li.strolch.utils.helper.StringHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class I18nMessage { + private static final Logger logger = LoggerFactory.getLogger(I18nMessage.class); + private ResourceBundle bundle; private String key; private Properties values; @@ -32,14 +37,18 @@ public class I18nMessage { public I18nMessage value(String key, String value) { DBC.INTERIM.assertNotEmpty("key must be set!", key); - DBC.INTERIM.assertNotEmpty("value must be set!", value); - this.values.setProperty(key, value); + this.values.setProperty(key, value == null ? "-" : value); return this; } public String formatMessage() { - String string = this.bundle.getString(this.key); - return StringHelper.replacePropertiesIn(this.values, EMPTY, string); + try { + String string = this.bundle.getString(this.key); + return StringHelper.replacePropertiesIn(this.values, EMPTY, string); + } catch (MissingResourceException e) { + logger.error("Key " + this.key + " is missing in bundle " + this.bundle.getBaseBundleName()); + return this.key; + } } @Override