diff options
author | Rüdiger Herrmann <ruediger.herrmann@gmx.de> | 2014-05-30 13:54:13 +0200 |
---|---|---|
committer | Rüdiger Herrmann <ruediger.herrmann@gmx.de> | 2014-06-01 11:59:21 +0200 |
commit | 02baeab4c44d26cb0147a23e688780a862025496 (patch) | |
tree | 36cd38b510437d61722e6b8b32d7f7514461a6c8 /org.eclipse.jgit/src/org/eclipse/jgit/nls | |
parent | 0b9bef49f4f29cbfefad2ce3235c1d037e983b1d (diff) | |
download | jgit-02baeab4c44d26cb0147a23e688780a862025496.tar.gz jgit-02baeab4c44d26cb0147a23e688780a862025496.zip |
Enable NLS / TranslationBundle to be used in OSGi
TranslationBundle#load() used to load resource bundles through
ResourceBundle#getBundle() without explicitly specifying a class loader.
In this case, the class laoder of the calling class (TranslationBundle
here) is used. This approach fails in runtime environments like OSGi
where there are multiple class loaders.
This change enables loading resource bundles in multi class loaders
environments. The fix is to pass the class loader of the
TranslationBundle-derived class to ResourceBundle#getBundle().
Bug: 436232
Change-Id: I39db61e012dc93ebf388a71bf6088a3310a22bac
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/nls')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/nls/TranslationBundle.java | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/nls/TranslationBundle.java b/org.eclipse.jgit/src/org/eclipse/jgit/nls/TranslationBundle.java index 2c745e1f3e..c85c179aa2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/nls/TranslationBundle.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/nls/TranslationBundle.java @@ -99,8 +99,8 @@ import org.eclipse.jgit.errors.TranslationStringMissingException; * {@link ResourceBundle#getBundle(String, Locale)} method to load a resource * bundle. See the documentation of this method for a detailed explanation of * resource bundle loading strategy. After a bundle is created the - * {@link #effectiveLocale()} method can be used to determine whether the - * bundle really corresponds to the requested locale or is a fallback. + * {@link #effectiveLocale()} method can be used to determine whether the bundle + * really corresponds to the requested locale or is a fallback. * * <p> * To load a String from a resource bundle property file this class uses the @@ -153,13 +153,17 @@ public abstract class TranslationBundle { * * @param locale * defines the locale to be used when loading the resource bundle - * @exception TranslationBundleLoadingException see {@link TranslationBundleLoadingException} - * @exception TranslationStringMissingException see {@link TranslationStringMissingException} + * @exception TranslationBundleLoadingException + * see {@link TranslationBundleLoadingException} + * @exception TranslationStringMissingException + * see {@link TranslationStringMissingException} */ - void load(Locale locale) throws TranslationBundleLoadingException { + void load(Locale locale) + throws TranslationBundleLoadingException { Class bundleClass = getClass(); try { - resourceBundle = ResourceBundle.getBundle(bundleClass.getName(), locale); + resourceBundle = ResourceBundle.getBundle(bundleClass.getName(), + locale, bundleClass.getClassLoader()); } catch (MissingResourceException e) { throw new TranslationBundleLoadingException(bundleClass, locale, e); } |