use toString() instead of cast String or it will fail when using Spring configtree#10980
Conversation
| @Override | ||
| public void init(KeycloakDeployment deployment, Object config) { | ||
| clientSecret = (String) config; | ||
| clientSecret = config.toString(); |
There was a problem hiding this comment.
@ianwallen thanks for submitting those changes. But I believe we need a better alternative here. Those changes will fix part of the problem, but if config is null we will get an NPE.
There was a problem hiding this comment.
I have made a change that should resolve the potential NPE issue.
Fix potential NPE issue if config was null.
abstractj
left a comment
There was a problem hiding this comment.
@pedroigor changes LGTM, but I would like your opinion before merging it.
ahus1
left a comment
There was a problem hiding this comment.
I haven't used config tree with Spring Boot yet. Looking at the APIs, this will return a ConfigTreePropertySource.Value which implements both CharSequence and InputStreamSource.
To retrieve a String, toString() with the null check looks fine to me. At the same time there are several other casts to String in this module. I suspect some of them might fail in a similar way.
I think it is OK to merge this, and I'd encourage the community to investigate if there are other similar issues. An example repository with a ready-to-test example app would be helpful.
Fix for #10979
By using toString() instead of cast (String), it is able to convert the configtree value correctly to a string value.