JDK-4250226 : ResourceBundle caches and does not check for updates when file has changed
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-06-28
  • Updated: 1999-06-28
  • Resolved: 1999-06-28
Related Reports
Duplicate :  
Description

Name: rlT66838			Date: 06/28/99


If you read a ResourceBundle twice and the ResourceBundle's
content changed between the two getBundle() calls, ResourceBundle
does not reread the file instead it just returns a copy from its
hashtable.
For example this source-code:

import java.util. *;
import java.io. *;

class ResourceBundleTest {

    private ResourceBundle bundle;

    public void openResourceBundle()
    {
	try {
	    bundle = ResourceBundle.getBundle("test");
	}
	catch (MissingResourceException e)
	    {
		e.printStackTrace();
	    }
    }

    public void createResourceFile(String content)
    {
	try {
	    FileWriter file = new FileWriter("test.properties");
	    file.write("content " + content + "\n");
	    file.close();
	}
	catch (IOException e)
	    {
		e.printStackTrace();
	    }
    }
    
    public void viewResource()
    {
	System.out.println("Content: " + bundle.getString("content")+"\n");
    }

    public static void main (String args[])
    {
	ResourceBundleTest test = new ResourceBundleTest();
	
	test.createResourceFile("111111111");
	test.openResourceBundle();
	test.viewResource();

	test.createResourceFile("222222222");
	test.openResourceBundle();
	test.viewResource();
    }

}

It should display:

Content: 111111111

Content: 222222222

but it displays:

Content: 111111111

Content: 111111111

The Resourcebundle Code should look at the filesystem if the file
has changed since the last read and use the newer one.
(Review ID: 84921) 
======================================================================

Comments
WORK AROUND Name: rlT66838 Date: 06/28/99 none (restart the application is not possible) ======================================================================
11-06-2004