JDK-4919638 : Unicode property files for PropertyResourceBundles - again
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9,windows_xp
  • CPU: x86,sparc
  • Submitted: 2003-09-09
  • Updated: 2014-07-11
  • Resolved: 2006-04-06
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: gaG125535			Date: 09/09/2003


A DESCRIPTION OF THE REQUEST :
There is a valid need for resource files that are encoded in character sets other than Latin-1.  My application has a need for property files to be stored in UTF-8.  The current Property class and ResourceBundle classes do not allow this, but hard-code the Latin-1 encoding.

This is a duplicate of RFE 4221013, which in turn is a duplicate of several others, all of which have been marked as "Closed, will not be fixed".  The explanation is that one should use the native2ascii tool to convert files from UTF-8 to ASCII or Latin-1, with \u escapes for characters outside this range.



JUSTIFICATION :
For normal product localisation, I believe the Latin-1 encoding requirement is acceptable.  However, if the application expects end-users to edit the properties files to perform site-specific and customer-specific customisation, not localisation, then the Latin-1 encoding requirement is unreasonable; the user needs to be able to edit the file and see their native characters, not \u escapes.  Furthermore, the native2ascii tool is part of the SDK, not the JRE, so is not available to end users.

On one of the previous submissions of this RFE, the response was to use the Preferences API.  The Preferences API is not a replacement for property files for this usage - holding localised or customised strings in alternative languages.

Note that compatibility is not an issue - I am asking for the ability to set up new property files in new encodings, not an incompatible change to any existing property files.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A new method should be added to the Properties class, either load(InputStream inputStream, String encoding) or load(Reader inputReader), allowing the developer to load a Properties object from a stream or reader using a specific encoding rather than the hard-coded "8859_1".

A new constructor should be added to PropertyResourceBundle, PropertyResourceBundle(InputStream Stream, String encoding).  This new constructor would use the new Properties load method to load the resources from the stream in the specified encoding.

A new method should be added to ResourceBundle, ResourceBundle getBundle(String baseName, Locale locale, String encoding).  This method would use the new PropertyResourceBundle constructor, passing the specified encoding.

Alternatively, the code in ResourceBundle and Properties should be refactored with new protected or public methods so that I could create subclasses that implement my desired behaviour.  This cannot easily be done today, because many of the methods are private, and do not separate the file encoding issue from other actions.

None of these changes should invalidate existing code or existing Latin-1 property files.

CUSTOMER SUBMITTED WORKAROUND :
I must either copy all the source code for the Properties, ResourceBundle, and PropertyResourceBundle, modifying the names and encoding to allow UTF-8 encoded property files, or I have to pass a custom class loader to ResourceBundle.getBundle that manufactures a filter stream to translate from UTF-8 to ascii on the fly (basically, embed the functionality of native2ascii in my program).

Neither of these approaches is desirable, since both require maintaining a substantial chunk of code that must duplicate and keep in step with standard Java classes or Sun source code.
(Incident Review ID: 190818) 
======================================================================

Comments
EVALUATION We are adding a pair of load(Reader)/store(Writer) methods into Properties class see#4094886 and adding a new constructor PropertyResourceBundle(Reader) for PropertyResourceBundle class (see #6204853), this should be good enough to address this RFE. Close this one as the dup of above two RFEs
06-04-2006

EVALUATION This is most likely addressed by the fix for 4749531, in which methods were added to Properties to load and save a properties list via XML. ###@###.### 2003-09-09
09-09-2003