Issue Details (XML | Word | Printable)

Key: CONFIGURATION-345
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Oliver Heger
Reporter: Guillaume Darmont
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Configuration

PropertiesConfiguration does not use the default encoding to load files

Created: 03/Nov/08 10:45 AM   Updated: 22/Aug/09 07:36 PM
Component/s: None
Affects Version/s: 1.5
Fix Version/s: 1.6

Time Tracking:
Not Specified

Environment: Win XP / Sun JVM 1.5.0_14

Resolution Date: 08/Nov/08 09:17 PM


 Description  « Hide
The piece of code
PropertiesConfiguration.java
// initialization block to set the encoding before loading the file in the constructors
    {
        setEncoding(DEFAULT_ENCODING);
    }

seems to set correctly the default encoding, but this block is called after "super()" in constructors.

So when using either PropertiesConfiguration(java.io.File file), PropertiesConfiguration(java.lang.String fileName) or PropertiesConfiguration(java.net.URL url), the super() statement is called, and it loads the file without the default encoding.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible added a comment - 03/Nov/08 11:05 AM
Well, Java does not really support a special encoding for a property file. According the spec http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#store(java.io.OutputStream,%20java.lang.String) a property file is always in ISO-8859-1 encoding.

Guillaume Darmont added a comment - 03/Nov/08 11:28 AM
That's exactly the point.
If I have an ISO-8859-1 properties file (as it must be) but the current JVM default encoding is UTF-8, the 3 constructors above will use UTF-8 since they call the load() method (via super(...)) before the block setEncoding(DEFAULT_ENCODING).

I'm not used to work with initialization block so I checked the behavior using the debugger to understand why the "setEncoding(DEFAULT_ENCODING)" wasn't called before "load()".

Hope this helps.


Oliver Heger added a comment - 08/Nov/08 09:17 PM
A fix was applied in revision 712431 (and also ported to the configuration2 branch).

Hm, in "Effective Java" (http://java.sun.com/docs/books/effective/) Joshua Bloch advises against calling protected non-final methods in constructors. Here we see why.