ResourceBundle and internationalisation

Discussion in 'Plugin Development' started by desht, Aug 1, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    desht

    Hi, I'm working on internationalising my plugin right now, using the Java ResourceBundle API. It's working, but there is one really annoying little problem - if I do a /reload (reload command from General) to reload the server after modifying my plugin JAR, the message resource bundle can no longer be found:

    Code:
    ...
    Caused by: java.util.MissingResourceException: Can't find bundle for base name datafiles.messages, locale en_US
            at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1539)
            at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1278)
            at java.util.ResourceBundle.getBundle(ResourceBundle.java:733)
            at me.desht.chesscraft.Messages.<clinit>(Messages.java:9)
            ... 14 more
    
    If I restart the server from cold, the resource bundle is found OK, so I assume there's some internal cache somewhere getting confused. I thought of trying a ResourceBundle.clearCache() from my plugin disable method, but that didn't help.

    Not a show-stopper, but it is irritating - slows down testing when I'm busy modifying my plugin code. Anyone else encountered this, know of any workarounds...?
     
  2. Offline

    Shamebot

    I know other plugins having a similar problem, when reloading the server with a new jar .getRessourceAsStream throws an exception, and it turned out it's a java bug. Dunno if it's the same for you.
     
  3. I'd just write your own interface, it's not that hard and I did it for my Warzone plugin and it works well :)

    The source is up on my github in the Languages folder if you're interested.
     
  4. Offline

    totemo

    desht Did you find any solution to this issue while staying within the confines of the Bukkit API?
     
  5. did you pass the correct classloader when constructing the resource bundle?
     
  6. Offline

    desht

  7. Offline

    totemo

    Oh, that's neat.

    I spent some time looking into it and discovered that the ClassLoader.getResourceAsStream() method is consistently returning null (http://forums.bukkit.org/threads/ge...eturns-null-after-reload.145546/#post-1684726), which would indicate either that the ClassLoader is close()d or perhaps the underlying JAR file is closed (or some lower level object). I'm not sure if that's Bukkit introducing some kind of file system access optimisation or whether it's a bug in the JRE. Your solution works because you directly access the JAR file.

    Interestingly enough, the problem still manifests if you create a new, separate URLClassLoader and initialise it with the same URLs as the PluginClassLoader, so there is some sharing going on at that level.
     
Thread Status:
Not open for further replies.

Share This Page