/hg/icedtea-web: Fixed "could not clear cache" message and cache...

Omair Majid omajid at redhat.com
Mon Sep 9 08:55:30 PDT 2013


Hi,

On 09/09/2013 11:07 AM, Andrew Azores wrote:
> On 09/09/2013 03:51 AM, Jiri Vanek wrote:
>> if you implement properties  singleton like this:
>>
>>
>> getSingleton(){
>> if (singleton=null) then loadSingleton()
>> }
>>
>> getMessage(key){
>> return getSingleton().getMessage(key)
>> }

This is not thread safe (if that matters). Simply adding 'sycnhronized'
to getSingleton will make it much more expensive.

Use an enum. It's the simplest way to make a singleton safely:

enum Singleton {
  INSTANCE;
}

> diff --git a/tests/test-extensions/net/sourceforge/jnlp/tools/MessageProperties.java b/tests/test-extensions/net/sourceforge/jnlp/tools/MessageProperties.java
> new file mode 100644
> --- /dev/null
> +++ b/tests/test-extensions/net/sourceforge/jnlp/tools/MessageProperties.java
> @@ -0,0 +1,79 @@
> +package net.sourceforge.jnlp.tools;

You are missing the license header here.

> +    /* eg if given locale "de", returns a PropertyResourceBundle using
> +     * "net/sourceforge/jnlp/resources/Messages_de.properties".
> +     * if given "en", the same but using "net/sourceforge/jnlp/resources/Messages.properties"
> +     */
> +    private static PropertyResourceBundle getMessageBundleFromLocale(Locale locale) throws IOException {
> +        final ClassLoader cl = MessageProperties.class.getClassLoader();
> +
> +        final String localizationCode;
> +        if (locale == Locale.en) {
> +            localizationCode = "";
> +        } else {
> +            localizationCode = "_" + locale.toString();
> +        }
> +
> +        final String path = resourcePath + localizationCode + resourceExtension;
> +        return new PropertyResourceBundle(cl.getResourceAsStream(path));
> +    }

This looks like it's re-inventing the wheel. This fallback is already
part of ResourceBundle class [1][2]. You can just use that and avoid
implementing this method entirely. As a bonus, you will get support for
Country and Variant along with Language.

Thanks,
Omair

[1] http://docs.oracle.com/javase/tutorial/i18n/resbundle/concept.html
[2]
http://docs.oracle.com/javase/6/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String,
java.util.Locale, java.lang.ClassLoader)
-- 
PGP Key: 66484681 (http://pgp.mit.edu/)
Fingerprint = F072 555B 0A17 3957 4E95  0056 F286 F14F 6648 4681



More information about the distro-pkg-dev mailing list