Skip to content

Instantly share code, notes, and snippets.

@mathifonseca
Created October 8, 2014 15:00
Show Gist options
  • Save mathifonseca/abe76eab1a4a95124097 to your computer and use it in GitHub Desktop.
Save mathifonseca/abe76eab1a4a95124097 to your computer and use it in GitHub Desktop.
GRAILS - ConfigObject curiosity

What happens if you look for a config key in a groovy.util.ConfigObject and it does not exist?

It should return null or an empty map. The latter is true.

But the curious thing is that the key is created if it does not exist! It seems pretty odd and useless, but they must have a reason...

Here is the code that does that in this class:

public Object getProperty(String name) {
	if ("configFile".equals(name))
    		return this.configFile;

	if (!containsKey(name)) {
	    ConfigObject prop = new ConfigObject(this.configFile);
	    put(name, prop);
	    return prop;
	}

	return get(name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment