groovy
  1. groovy
  2. GROOVY-6304 Configslurper Issues
  3. GROOVY-3521

ConfigSlurper cannot parse property files with nested properties correctly

    Details

    • Type: Sub-task Sub-task
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6, 1.6.2
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I have a properties file name "my.properties":

      level1.level2.key1   1
      level1.level2.key2   2
      level1.level2        3
      

      When the following code is run...

      def loadProperties(filename) {
          Properties properties = new Properties()
          properties.load(new FileInputStream(filename))
          properties
      }
      
      def properties = loadProperties("my.properties")
      def config = new ConfigSlurper().parse(properties)
      
      println "properties:     " + properties
      println "slurper:        " + slurper
      println "property value: " + properties.getProperty("level1.level2.key1")
      println "slurper value:  " + slurper.level1.level2.key1
      

      ...it prints

      properties:     ["level1.level2":"3", "level1.level2.key2":"2", "level1.level2.key1":"1"]
      slurper:        ["level1":["level2":"3", "level2.key2":"2", "level2.key1":"1"]]
      property value: 1
      Caught: groovy.lang.MissingPropertyException: No such property: key1 for class: java.lang.String
              at config_slurper.run(config_slurper.groovy:13)
              at config_slurper.main(config_slurper.groovy)
      

      I would expect to also get "1" for "level1.level2.key1" via the ConfigSlurper (as I get it via Java's Properties). Looks like the internal map representation cannot handle such cases.

        Activity

        Pascal Schumacher made changes -
        Field Original Value New Value
        Parent GROOVY-6304 [ 148075 ]
        Issue Type Bug [ 1 ] Sub-task [ 7 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Rene Scheibe
          • Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: