Bug 576335 - getString: Avoid throw & catch of MissingResourceException
getString() needs to check the key with ResourceBundle#containsKey().
This avoids that a MissingResourceException could be caused and thus the
overhead of creating multiple exceptions and catching them to implement
the fallback behavior.
Additional refactoring: Replace
!file.trim().isEmpty()
->!file.isBlank()
Change-Id: If40627146628c9302487b128daf678613c148899
Signed-off-by: Karsten Thoms <karsten.thoms@karakun.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/185961
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Jörg Kubitz <jkubitz-eclipse@gmx.de>
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java
index 316a718..fadefea 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ResourceAction.java
@@ -15,7 +15,6 @@
-import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jface.action.Action;
@@ -47,14 +46,7 @@
* <code>null</code>)
*/
protected static String getString(ResourceBundle bundle, String key, String defaultValue) {
-
- String value= defaultValue;
- try {
- value= bundle.getString(key);
- } catch (MissingResourceException x) {
- }
-
- return value;
+ return bundle.containsKey(key) ? bundle.getString(key) : defaultValue;
}
/**
@@ -152,7 +144,7 @@
setDescription(getString(bundle, descriptionKey, null));
String file= getString(bundle, imageKey, null);
- if (file != null && !file.trim().isEmpty())
+ if (file != null && !file.isBlank())
setImageDescriptor(ImageDescriptor.createFromFile(getClass(), file));
}
}