Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3186

ConfigSlurper only allows a single block for any given name

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7-beta-1
    • 1.7.2, 1.8-beta-1
    • None
    • None
    • Patch

    Description

      If you specify more than one block for the same key in a ConfigSlurper script, the second overwrites the first. For example, given this script:

      topNode {
        one = "1"
      }
      
      topNode {
        two = "2"
      }
      

      the "slurped" config will only contain topNode.two:"2". Obviously this is a trivial example, but the point is that the whole of the first block is ignored, a more realistic grails-inspired example would be

      log4j {
        logger {
          foo.bar = "debug"
          // many more logger definitions here
        }
      }
      
      // extra block added later
      'log4j.logger' {
        extraLogger = "info"
      }
      

      All the first set of logger definitions are lost.

      I think this is because the overridden invokeMethod in ConfigSlurper always creates a new ConfigObject at the start of a nested block, rather than checking whether a block already exists for this name. The attached patch (diff against latest trunk) changes this to reuse the existing ConfigObject so that the blocks are merged rather than one overriding the other, which seems more intuitive behaviour to me.

      Attachments

        1. ConfigSlurper.diff
          1 kB
          Ian Roberts

        Activity

          People

            guillaume Guillaume Sauthier
            button_boxer Ian Roberts
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: