-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Requesting config-server for config of a service will throw a NullPointException when using yml configuration which contains an empty list([]).
This only occurs when using accept header application/vnd.spring-cloud.config-server.v2+json
which is the new default when using a config-client.
Problem is that the origin is null at https://github.com/spring-cloud/spring-cloud-config/blob/v2.2.2.RELEASE/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/PassthruEnvironmentRepository.java#L101
Reproduction
Create spring-config-server from https://start.spring.io/ and setup a local repo.
(Using Spring Boot 2.2.5)
Add following sample (demo-client.yml
) into repo and commit
foo: bar
# Emptylist will throw NullPointerException
emptylist: []
Start config-server and try to access this configuration file.
Working (old without accept header)
curl http://localhost:8888/demo-client/default
{
"name": "demo-client",
"profiles": [
"default"
],
"label": null,
"version": "91e04f01593514508554c85eb42f6b000dd10411",
"state": null,
"propertySources": [
{
"name": "D:/temp/configserver-repo/demo-client.yml",
"source": {
"foo": "bar",
"list": ""
}
}
]
}
Exception
curl -H "accept: application/vnd.spring-cloud.config-server.v2+json" http://localhost:8888/demo-client/default
{
"timestamp": "2020-03-11T13:26:01.485+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Could not construct context for config=demo-client profile=default label= includeOrigin=true; nested exception is java.lang.NullPointerException",
"path": "/demo-client/default"
}
Newer config-clients are accessing this through the new media-type (config-sever.v2).
See https://github.com/spring-cloud/spring-cloud-config/blob/v2.2.2.RELEASE/spring-cloud-config-client/src/main/java/org/springframework/cloud/config/client/ConfigServicePropertySourceLocator.java#L254