Skip to content

Missing separator between list elements leads to unintended merge #814

@andymalakov

Description

@andymalakov

We love HOCON relaxed syntax that "allows omitting commas as long as there's a newline". However this may lead to unintended consequences when user accidentally omits both comma and new line characters when enumerating list elements:

  aList = [
          {
              name = "ONE",
          }
          {
              name = "TWO",
          }          {   // <---------- this line will be ignored!
              name = "THREE",
          }
  ]

Expected behavior: some kind of warning or error message indicating that input contains ; sequence that will be ignored.

Actual behavior: objects "TWO" and "THREE" merged.

Java code:

package deltix.ember.app;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

public class ObjectLostSample {

    private static final String HOCON = """
            aList = [
                    {
                        name = "ONE",
                    }
                    {
                        name = "TWO",
                    } {                   // this line will be ignored!
                        name = "THREE",
                    }
            ]
            """;

    public static void main (String [] args) {
        Config config = ConfigFactory.parseString(HOCON);

        var aList = config.getObjectList("aList");
        System.out.println("aList size: " + aList.size());
        System.out.println("aList (0): " + aList.get(0));
        System.out.println("aList (1): " + aList.get(1));
    }
}

Prints:

aList size: 2
aList (0): SimpleConfigObject({"name":"ONE"})
aList (1): SimpleConfigObject({"name":"THREE"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions