Exception when loading message.properties

Hello!

(see update below)

In our code we load the messages using java.util.ResourceBundle#getBundle(java.lang.String)

...
private static final String BUNDLE_NAME = "messages";
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
...

The raw exception when calling getBundle() is

2018-04-23 17:24:43.842 p4u_ios[14534:816098] *** Terminating app due to uncaught exception 'java.lang.ExceptionInInitializerError', reason: 'java.lang.ExceptionInInitializerError
	at MyMasterTableViewController.viewDidLoad(MyMasterTableViewController.java:60)
	at apple.uikit.c.UIKit.UIApplicationMain(Native Method)
	at Main.main(Main.java:98)
Caused by: java.lang.IllegalArgumentException: length <= 0: 0
	at java.nio.charset.CoderResult.malformedForLength(CoderResult.java:124)
	at java.nio.charset.CharsetDecoderICU.decodeLoop(CharsetDecoderICU.java:145)
	at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:306)
	at java.io.InputStreamReader.read(InputStreamReader.java:246)
	at java.io.BufferedReader.fillBuf(BufferedReader.java:145)
	at java.io.BufferedReader.readChar(BufferedReader.java:263)
	at java.io.BufferedReader.read(BufferedReader.java:253)
	at java.util.Properties.load(Properties.java:289)
	at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:64)
	at java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:520)
	at java.util.ResourceBundle.handleGetBundle(ResourceBundle.java:542)
	at java.util.ResourceBundle.getBundle(ResourceBundle.java:228)
	at java.util.ResourceBundle.getBundle(ResourceBundle.java:139)
	at ui.Messages.<clinit>(Messages.java:20)
	... 3 more

After debugging a little bit I found in …/.moe/moe-sdk-1.4.2/sdk/moe-core-sources.jar!/java/util/ResourceBundle.java:503

Class<?> bundleClass = Class.forName(bundleName, true, loader);

Which had the following state:

loadBase = true
base = "messages"
locale = {Locale@2318} "de_KCFLOCALECOUNTRYCODEKEY"
loader = {BootClassLoader@2319} 
localeName = "de_KCFLOCALECOUNTRYCODEKEY"
bundleName = "messages_de_KCFLOCALECOUNTRYCODEKEY"
cacheKey = {BootClassLoader@2319} 
cached = null
loaderCache = {Hashtable@2322}  size = 0
bundle = null

Is the locale correct? I initialised Locale with

private static void initLocales() {
    NSLocale nsLocale = NSLocale.autoupdatingCurrentLocale();
    String languageCode = nsLocale.objectForKey(Foundation.NSLocaleLanguageCode()).toString();
    Locale.setDefault(new Locale(languageCode, NSLocaleCountryCode()));
}

I think this is a bug.

Update 24. Apr. 2018:
This behaviour was caused by a resource bundle with latin-1 encoding (as specified by Java) containing german umlaute. But the bundle is read as UTF-8 encoded file (as specified by Android). Running iconv on the bundle did solve the error.

iconv --from-code=latin1 --to-code=UTF-8 latin_messages_de.properties > utf8_messages_de.properties 

Nonetheless I think the error message should contain a clue about the possible cause of the problem.

Regards
Niels

Hi Niels,

thank you for this update. I opened an issue to track this: https://github.com/multi-os-engine/multi-os-engine/issues/125

Best Regards,
Gergely