Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6304 Configslurper Issues
  3. GROOVY-3521

ConfigSlurper cannot parse property files with nested properties correctly

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.6, 1.6.2
    • None
    • groovy-jdk
    • None

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rene.scheibe Rene Scheibe
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: