[ 
https://issues.apache.org/jira/browse/CONFIGURATION-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12703347#action_12703347
 ] 

Oliver Heger commented on CONFIGURATION-382:
--------------------------------------------

I did some tests, but cannot reproduce the problem.

What exactly do you mean by "When we change the property value"? Do you change 
the value programmatically by calling {{setProperty()}} or do you change the 
properties file manually so that it gets reloaded?

Also, I do not really understand the content of your properties file. The line
{{1. This is comment.}}
is not a valid comment line as it does not start with a comment character like 
{{#}}.

Below is a test case I added to _TestPropertiesConfiguration_. It works with 
two {{PropertiesConfiguration}} objects that access the same file. So I can use 
one object for changing the file and see whether the other one picks up the 
change.

{code}
    public void testCommentsWithReload() throws ConfigurationException
    {
        final String comment = "A test comment";
        PropertiesConfiguration c = new PropertiesConfiguration();
        c.setProperty(PROP_NAME, PROP_VALUE);
        c.getLayout().setComment(PROP_NAME, comment);
        c.setFile(testSavePropertiesFile);
        c.save();
        conf.clear();
        conf.setFile(testSavePropertiesFile);
        conf.load();
        assertEquals("Wrong value", PROP_VALUE, conf.getString(PROP_NAME));
        assertEquals("Wrong comment", comment, conf.getLayout()
                .getCanonicalComment(PROP_NAME, false));
        conf.setReloadingStrategy(new FileAlwaysReloadingStrategy());
        final String newValue = "Another value";
        c.setProperty(PROP_NAME, newValue);
        c.save();
        assertEquals("Wrong value after reload", newValue, conf
                .getString(PROP_NAME));
        assertEquals("Wrong comment after reload", comment, conf.getLayout()
                .getCanonicalComment(PROP_NAME, false));
        conf.save();
    }
{code}

This seems to work. The comment is not duplicated. (I also inspected the file 
manually after it was written at the end of the test).

Can you perhaps provide a code fragment that reproduces the problem? Thanks.

> Duplicate comments are created in Property file when using 
> setReloadingStrategy
> -------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-382
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-382
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: File reloading
>         Environment: all platforms
>            Reporter: Anjugaselvan
>            Priority: Critical
>
> Whenever we set a property value in a .properties file, the comments are 
> created twice. For example, the following is the content of the property file 
> initially.
> # This is comment.
> PropName = PropValue1
> When we change the property value, the comment line is updated twice.
> # This is comment.
> # This is comment.
> PropName = PropValue2
> This issue is seen only when we use setReloadingStrategy() method to notify 
> the property change event to another running process.
> We are using the following code to notify the process which uses this 
> property.
> propConf.setReloadingStrategy(new FileChangedReloadingStrategy());
> If we remove the above code, we do not see this issue. But if we do not use 
> this method, the process which uses this property doesnt get this new value.

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

Reply via email to