Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceBundle.Control is not supported in named modules #620

Open
Peter-Maeding opened this issue Oct 30, 2024 · 3 comments
Open

ResourceBundle.Control is not supported in named modules #620

Peter-Maeding opened this issue Oct 30, 2024 · 3 comments

Comments

@Peter-Maeding
Copy link

I have a lanterna app that uses modules. After setting a default locale other than English I noticed that the app still shows the english values (e.g. LocalizedString.Cancel.toString() will always return "Cancel"). This works as expected when used in an app without modules.

After some debugging I found that lanterna fails to load its resource bundles in BundleLocator on line 73:

return ResourceBundle.getBundle(bundleName, locale, loader, new UTF8Control());

This code throws java.lang.UnsupportedOperationException: ResourceBundle.Control not supported in named modules

The javadoc of ResourceBundle.Control states the following about this problem:

ResourceBundle.Control is designed for an application deployedin an unnamed module, for example to support resource bundles innon-standard formats or package localized resources in a non-traditional convention. ResourceBundleProvider is the replacement for ResourceBundle.Control when migrating to modules. UnsupportedOperationException will be thrown when a factory method that takes the ResourceBundle.Control parameter is called.
[...]
ResourceBundle.Control is not supported in named modules. If the ResourceBundle.getBundle method with a ResourceBundle.Control is called in a named module, the method will throw an UnsupportedOperationException. Any service providers of ResourceBundleControlProvider are ignored in named modules.

@avl42
Copy link
Contributor

avl42 commented Nov 4, 2024 via email

@Peter-Maeding
Copy link
Author

I looked a bit into how java loads resource bundles. It seems property bundles used to be loaded with the ISO-8859-1 charset. If I understand the comments correctly lanterna used the custom Control to use UTF-8 instead.
As of java 9 the default encoding for resource bundles is already UTF-8 and can be set to ISO-8859-1 by a system property. So for newer java versions at least the control doesn't seem necessary.

I also took a look at the ResourceBundleProvider thing and unfortunately it was introduced with java 9, so no chance there.

The only simple solution i can think of right now is to only use the Control in java 8 and below. Something along the lines of this:

private ResourceBundle getBundle(Locale locale) {
    if (Runtime.version().major() < 9) {
        return ResourceBundle.getBundle(bundleName, locale, loader, new UTF8Control());
    } else {
        return ResourceBundle.getBundle(bundleName, locale, loader);
    }
}

That does kinda feel like a hack though. I'll have to think more about a better solution.

Named modules are not essential for my project, I'd just rather use them (it's a personal project after all). For the time beeing I can live with the english defaults in the few places my app relies on lanterna's localization.

@avl42
Copy link
Contributor

avl42 commented Nov 5, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants