You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Guillaume Darmont (JIRA)" <ji...@apache.org> on 2008/11/03 11:46:44 UTC

[jira] Created: (CONFIGURATION-345) PropertiesConfiguration does not use the default encoding to load files

PropertiesConfiguration does not use the default encoding to load files
-----------------------------------------------------------------------

                 Key: CONFIGURATION-345
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-345
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.5
         Environment: Win XP / Sun JVM 1.5.0_14
            Reporter: Guillaume Darmont


The piece of code

{code:title=PropertiesConfiguration.java}
    // initialization block to set the encoding before loading the file in the constructors
    {
        setEncoding(DEFAULT_ENCODING);
    }
{code}

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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CONFIGURATION-345) PropertiesConfiguration does not use the default encoding to load files

Posted by "Guillaume Darmont (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12644692#action_12644692 ] 

Guillaume Darmont commented on CONFIGURATION-345:
-------------------------------------------------

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.

> PropertiesConfiguration does not use the default encoding to load files
> -----------------------------------------------------------------------
>
>                 Key: CONFIGURATION-345
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-345
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Win XP / Sun JVM 1.5.0_14
>            Reporter: Guillaume Darmont
>
> The piece of code
> {code:title=PropertiesConfiguration.java}
>     // initialization block to set the encoding before loading the file in the constructors
>     {
>         setEncoding(DEFAULT_ENCODING);
>     }
> {code}
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CONFIGURATION-345) PropertiesConfiguration does not use the default encoding to load files

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-345?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oliver Heger resolved CONFIGURATION-345.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.6

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.

> PropertiesConfiguration does not use the default encoding to load files
> -----------------------------------------------------------------------
>
>                 Key: CONFIGURATION-345
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-345
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Win XP / Sun JVM 1.5.0_14
>            Reporter: Guillaume Darmont
>            Assignee: Oliver Heger
>             Fix For: 1.6
>
>
> The piece of code
> {code:title=PropertiesConfiguration.java}
>     // initialization block to set the encoding before loading the file in the constructors
>     {
>         setEncoding(DEFAULT_ENCODING);
>     }
> {code}
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CONFIGURATION-345) PropertiesConfiguration does not use the default encoding to load files

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-345?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12644688#action_12644688 ] 

Joerg Schaible commented on CONFIGURATION-345:
----------------------------------------------

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.

> PropertiesConfiguration does not use the default encoding to load files
> -----------------------------------------------------------------------
>
>                 Key: CONFIGURATION-345
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-345
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Win XP / Sun JVM 1.5.0_14
>            Reporter: Guillaume Darmont
>
> The piece of code
> {code:title=PropertiesConfiguration.java}
>     // initialization block to set the encoding before loading the file in the constructors
>     {
>         setEncoding(DEFAULT_ENCODING);
>     }
> {code}
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.