Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7-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.