Hey guys, I had in a project the following:
String variable = grailsApplication.config.grails.property.name + grailsApplication.config.grails.anotherproperty.name
And was working for almost a year but suddenly it stop working and throwing an error regarding the ConfigObject doesn’t have a plus method, did something similar happened to anyone?
Did someone knows why it was working and suddenly stop working ?
It doesn’t work because one of ‘property.name’ or ‘anotherproperty.name’ is not set.
If some option is not set, then ConfigSlurper return instance of ConfigObject.
That’s a common mistake.
Good news is that empty ConfigObject can be casted to false by the Groovy Truth.
Thus, to avoid this kind of mistakes and get null instead of ConfigObject you can use Elvis operator write something like:
// return empty list if supportedLocales isn't set grailsApplication.config.supportedLocales ?:  // return null if defaultLocale isn't set grailsApplication.config.defaultLocale ?: null