Empty YAML entry wipes out grails config
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behavior
Sometimes I have environment specific yaml entries:
```
environments:
production:
grails:
serverURL: http://example.com
```
then for some reason I might comment an entry out:
```
environments:
production:
grails:
# serverURL: http://example.com
```
So I've left the vesitigial grails: tag, which doesn't do anything, but seems harmless.
However, it's not as harmless as it looks, because it wipes out the config hierarchy below grails.
So for example, in grails.plugin.springsecurity.ReflectionUtils.
```
static ConfigObject getSecurityConfig() {
def grailsConfig = getApplication().config
if (grailsConfig.grails.plugins.springsecurity) {
log.error "Your security configuration settings use the old prefix 'grails.plugins.springsecurity' but must now use 'grails.plugin.springsecurity'"
}
grailsConfig.grails.plugin.springsecurity
}
```
in this code, grailsConfig.grails is unexpectedly an empty object, and thus everything fails.
### Actual Behaviour
Everything basically fails if you do this, because the entire grails config is corrupted.
While it's easy to work around once you figure it out, you can spend days trying to track this down, because intuitively an empty grails: tag ought to be harmless.... and since this can come into existence in an environment specific way.. it's worse again, because everyting can be fine in development, and then in production it goes haywire.
I wasn't able to track down the exact moment the code goes wrong, but I do know that by line 85 of org.grails.config.yaml.YamlPropertySourceLoader.java, the result was wrong.
### Steps To Reproduce
_No response_
### Environment Information
_No response_
### Example Application
_No response_
### Version
5.0.3
Contributor guide
Research direction
Start in org.grails.config.yaml.YamlPropertySourceLoader.java around line 85, where the issue reports that the parsed result is already incorrect. Compare the two YAML examples and trace how an empty grails mapping is merged with the existing configuration. Done means a commented-out child entry does not replace the grails configuration hierarchy with an empty object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100