groovy
  1. groovy
  2. GROOVY-4957

ConfigObject doesn't fully create hierarchy

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8.0, 1.8.1
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      windows 7 64 bit, jdk 1.6.0_25 (32bit)
    • Number of attachments :
      4

      Description

      When writing a ConfigObject with a deep hierarchy, where some levels have no siblings, to file, some levels of the hierarchy get lost.

      See the following code snipet

      def config = new ConfigObject()
      config.db.hibernate.connection.url='jdbc:h2:file:C:/Temp/database;AUTO_SERVER=true'
      config.db.hibernate.connection.username='sa'
      config.db.hibernate.connection.password=''
      
      def file = new File('C:/Temp/config.groovy')
      file.withWriter { writer ->
          config.writeTo(writer)
      }
      

      This produces a file like this:

      connection {
      	url="jdbc:h2:file:C:/Temp/database;AUTO_SERVER=true"
      	username="sa"
      	password=""
      }
      

      What I would expect is:

      db {
      	hibernate {
      		connection {
      			url="jdbc:h2:file:C:/Temp/database;AUTO_SERVER=true"
      			username="sa"
      			password=""
      		}
      	}
      }
      
      1. ConfigObject.diff
        6 kB
        Dieter Rehbein
      2. ConfigObject.groovy
        7 kB
        Dieter Rehbein
      3. ConfigObjectWriter.groovy
        2 kB
        Dieter Rehbein
      4. Groovy4957Bug.groovy
        2 kB
        Dieter Rehbein

        Activity

        Hide
        Dieter Rehbein added a comment - - edited

        Since I really needed this bug to be fixed, I've done it myself. I've completely rewritten the writeTo(Writer) method (IMHO it's much simpler now and easier to read) and added a new unit-test. All unit tests succeeded with this change (I made the changes based on groovy 1.8.6).

        You might also use the attached ConfigObjectWriter, if you need a fix, before a new version of groovy is available.

        Hope, it helps

        best regards
        Dieter

        Show
        Dieter Rehbein added a comment - - edited Since I really needed this bug to be fixed, I've done it myself. I've completely rewritten the writeTo(Writer) method (IMHO it's much simpler now and easier to read) and added a new unit-test. All unit tests succeeded with this change (I made the changes based on groovy 1.8.6). You might also use the attached ConfigObjectWriter, if you need a fix, before a new version of groovy is available. Hope, it helps best regards Dieter
        Hide
        Guillaume Laforge added a comment -

        Woud you mind attaching a diff with the original versions, as it's easier to understand the changes you've done?
        You could as well issue a pull request through github if you prefer.

        Show
        Guillaume Laforge added a comment - Woud you mind attaching a diff with the original versions, as it's easier to understand the changes you've done? You could as well issue a pull request through github if you prefer.
        Hide
        Dieter Rehbein added a comment -

        I've added a diff-file.

        regards
        Dieter

        Show
        Dieter Rehbein added a comment - I've added a diff-file. regards Dieter
        Hide
        Dieter Rehbein added a comment -

        there is still an open Issue: if you have something like this:

        groups {
        	G1.name='G1'
        	G2.name='G2'
        	this.'3'.name='3'
        }
        

        you can parse it using a ConfigSlurper. If you try to write the resulting configuration using config.writeTo(..), an output will be produced, which can't be parsed again:

        groups {
        	G1.name='G1'
        	G2.name='G2'
        	3.name='3'
        }

        But the old implementation of writeTo had the same problem. IMHO it has to be checked, if the key is a valid identifier. If not, it has to be quoted and prefixed with this.

        Show
        Dieter Rehbein added a comment - there is still an open Issue: if you have something like this: groups { G1.name='G1' G2.name='G2' this .'3'.name='3' } you can parse it using a ConfigSlurper. If you try to write the resulting configuration using config.writeTo(..), an output will be produced, which can't be parsed again: groups { G1.name='G1' G2.name='G2' 3.name='3' } But the old implementation of writeTo had the same problem. IMHO it has to be checked, if the key is a valid identifier. If not, it has to be quoted and prefixed with this.

          People

          • Assignee:
            Unassigned
            Reporter:
            Erich Paul
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: