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

Peter commented on CONFIGURATION-753:
-------------------------------------

Thanks for looking at this again. There is some documentation covering it even 
if it isn't the main method of creating list properties. From the [javadoc in 
PropertiesConfig|https://github.com/apache/commons-configuration/blob/342f3b3be52bbbb188ad2fe81bb19ad688012123/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java#L110]:
 "If a key is used more than once, the values are appended like if they were on 
the same line separated with commas.". The code implementing this is in 
BaseConfiguration 
[here|https://github.com/apache/commons-configuration/blob/342f3b3be52bbbb188ad2fe81bb19ad688012123/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java#L52].
 I'm not sure if this is available for other file formats. There are tests for 
this behaviour 
[here|https://github.com/apache/commons-configuration/blob/342f3b3be52bbbb188ad2fe81bb19ad688012123/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java#L310].

RE. the java.util.Properties comparison, I think it is an intentional extension 
based on 
[this|https://github.com/apache/commons-configuration/blob/342f3b3be52bbbb188ad2fe81bb19ad688012123/src/main/java/org/apache/commons/configuration2/BaseConfiguration.java#L34].

Either way, I don't think it affects this issue. If you replace the two {{abc}} 
keys in the sample properties file above with a single, comma separated entry, 
the interpolation inconsistency would still be there.

> Handling of interpolation is inconsistent
> -----------------------------------------
>
>                 Key: CONFIGURATION-753
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-753
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Interpolation
>    Affects Versions: 2.5
>         Environment: Java 8, Configurations2 2.5
>            Reporter: Peter
>            Priority: Major
>         Attachments: test.properties
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> If a key is repeated in a configuration and then used in an interpolation 
> elsewhere, the behaviour is inconsistent. There are other tickets/discussions 
> about whether it should just pick the first value or not, but I don't think 
> it should do both.
> {code:java|title=/tmp/test.properties}
> abc = hello
> abc = world
> foo.one = ${abc}
> foo.two = prefix ${abc} suffix
> {code}
> {code:java|title=Demo.java (main)}
> Parameters params = new Parameters();
> FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new 
> FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
>     .configure(params.fileBased()
>         .setFileName("/tmp/test.properties")
>       );
> try {
>     FileBasedConfiguration config = builder.getConfiguration();
>     System.out.println(config.getString("foo.one"));
>     System.out.println(config.getString("foo.two"));
> } catch (ConfigurationException cex) {
>     // pass
> }
> {code}
> The output from the above is
> {noformat}
> hello 
> prefix [hello, world] suffix
> {noformat}
> In the first case, only the first value is being matched, in the second both 
> values (and [, ]) are used.
> I'd expect the output to either be
> {noformat:title=First value only}
> hello
> prefix hello suffix
> {noformat}
> or
> {noformat:title=Both values used}
> [hello, world]
> prefix [hello, world] suffix
> {noformat}
> I can work around whichever style is chosen but think it'd be much more 
> intuitive if both cases were handled the same.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to