spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Error when binding map in configuration properties if getter initialisation used.

Open chesterm8 opened this issue 10 years ago • 1 comments

I have detailed my problem and solution on stackoverflow, and will summarise here with more technical details about the root cause. http://stackoverflow.com/questions/36928559/null-pointer-when-creating-spring-boot-configurationproperties-mapstring-objec

Essentially if you have a Map<String, Object> in an @ConfigurationProperties file, initialising the map in the getter (eg using a ternary operator to initialise if null) causes binding to fail. Initialising the map in the constructor or as part of the field declaration fixes the issue.

The problem is that in AbstractNestablePropertyAccessor.setDefaultValue the default value is created correctly (line 1), but after the call to AbstractNestablePropertyAccessor.setPropertyValue (line 2) it has not been correctly persisted in the underlying object, so the call to AbstractNestablePropertyAccessor.getPropertyValue (line 3) returns null.

chesterm8 avatar Apr 29 '16 02:04 chesterm8

Thanks for the detailed analysis. This is a duplicate of #4650

wilkinsona avatar Apr 29 '16 05:04 wilkinsona