Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-753

Handling of interpolation is inconsistent

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5
    • Fix Version/s: None
    • Component/s: Interpolation
    • Labels:
      None
    • Environment:

      Java 8, Configurations2 2.5

      Description

      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.

      /tmp/test.properties
      abc = hello
      abc = world
      foo.one = ${abc}
      foo.two = prefix ${abc} suffix
      
      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
      }
      

      The output from the above is

      hello 
      prefix [hello, world] suffix
      

      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

      First value only
      hello
      prefix hello suffix
      

      or

      Both values used
      [hello, world]
      prefix [hello, world] suffix
      

      I can work around whichever style is chosen but think it'd be much more intuitive if both cases were handled the same.

        Attachments

        1. test.properties
          0.1 kB
          Peter

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                tpoliaw Peter
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 10m
                  10m