JDK-6388120 : REGRESSION:MissingResourceException when ResourceBundle.getString() called in constructor
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2006-02-21
  • Updated: 2010-04-02
  • Resolved: 2006-02-21
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REGRESSION :
A very simple test case has been supplied.  Basically, the class has a (non-static) ResourceBundle instance that is initialized at the class level and then used in the class constructor.

In JDK1.5.0, the test case works fine and correctly says "Hello".

In JDK1.6.0beta, a MissingResourceException is thrown.


REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
// BundleTest.java

package com.dj;

import java.util.ResourceBundle;

public class BundleTest {
	public ResourceBundle bundle = ResourceBundle.getBundle(BundleTest.class.getName());
	
	public static void main(String[] args)
	{
		new BundleTest();
	}

	public BundleTest() {
		System.out.println(bundle.getString("value.test"));
	}
}
//  ---

# And BundleTest.properties (sits in the com.dj package too):
value.test=Hello


Here is a variant of the test case that is also broken in the same way (so using the non-static ResourceBundle in the constructor is not the problem):

package com.dj;

import java.util.ResourceBundle;

public class BundleTest {
	public ResourceBundle bundle = ResourceBundle.getBundle(BundleTest.class.getName());
	
	public static void main(String[] args)
	{
		new BundleTest().sayHello();
	}

	public BundleTest() {
	}

	public void sayHello()
	{
		System.out.println(bundle.getString("value.test"));
	}
}


RELEASE LAST WORKED:
5.0 Update 3

RELEASE TEST FAILS:
mustang-beta

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the code to work against 1.6.0 exactly as it did against 1.5.0, i.e. the test case should say "Hello".
ACTUAL -
A MissingResourceException was thrown:

Exception in thread "main" java.util.MissingResourceException: Can't find resource for bundle java.util.ResourceBundle$1, key value.test
	at java.util.ResourceBundle.getObject(Unknown Source)
	at java.util.ResourceBundle.getString(Unknown Source)
	at com.dj.BundleTest.<init>(BundleTest.java:14)
	at com.dj.BundleTest.main(BundleTest.java:10)


APPLICATION NAME: [My company's software product]OBSERVED APPLICATION IMPACT:
This breaks one of the flagship applications that my company sells!

I think many people would see this - it is using the ResourceBundle API in a very trivial way.  Tthe brevity of the test case is testament to this!

There is a trivial workaround which is to make the ResourceBundle member static, but this may may not be suitable in all cases.

Release Regression From : mustang
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Comments
EVALUATION This is a duplicate of 6356571.
21-02-2006