Grails 4: Null value in the configuration has been converted to empty String
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
It looks like it's impossible to have a `null` value for a give configuration property in the `application.yml` as it is converted to an empty string. I think the problem is in [YamlPropertySourceLoader.java](https://github.com/grails/grails-core/blob/4.0.x/grails-core/src/main/groovy/org/grails/config/yaml/YamlPropertySourceLoader.java#L94) which is responsible for loading properties from the YAML. It calls an underline spring method which flattens the input map and somehow converts a `null` value to an empty string.
### Steps to Reproduce
1. Create a new Grails 4.0.3 application.
2. Define a property `test: null` in the application.yml
3. In the BootStrap.groovy add an assert to verify that the value is null as:
```
class BootStrap {
def grailsApplication
def init = { servletContext ->
assert grailsApplication.config.test == null
...
```
### Expected Behaviour
The value of the config property should be null.
### Actual Behaviour
The assertion would fail as the value is an empty String.
### Environment Information
- **Operating System**: macOS
- **Grails Version:** 4.0.3
- **JDK Version:** (AdoptOpenJDK)(build 1.8.0_232-b09)
- **Container Version (If Applicable):** N/A
### Example Application
https://github.com/puneetbehl/grails-config-problem.git
Contributor guide
Research direction
Start with grails-core/src/main/groovy/org/grails/config/yaml/YamlPropertySourceLoader.java at the referenced line and reproduce the issue using the linked grails-config-problem example. Trace how the YAML loader handles test: null, then verify that the BootStrap.groovy assertion passes and that the configuration value remains null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100