Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding to collection fails with unbound elements error if collection overridden in another property source #16290

Closed
mschallar opened this issue Mar 22, 2019 · 13 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@mschallar
Copy link

mschallar commented Mar 22, 2019

Hello,

after migrated from Spring Boot 1.5.3.RELEASE to 2.1.3.RELEASE we've encountered a bug(?) with property binding.

The example code can be found here. It's a simple application with one property class that receives values from the application.yml via the @ConfigurationProperties annotation.

Starting the DemoApplication works fine.

But starting the simple DemoApplicationTests does not work, as the demo uses "test" profile and therefore the property class receives it's values from "application-test.yml".

The excepton does NOT occur if "ignoreUnknownFields" is NOT present (i.e., set to true).

Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'demo-properties' to com.example.demo.DemoApplication$DemoProperties
	at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:249) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:225) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:208) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:190) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.bind(ConfigurationPropertiesBinder.java:83) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.bind(ConfigurationPropertiesBindingPostProcessor.java:107) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	... 43 common frames omitted
Caused by: org.springframework.boot.context.properties.bind.UnboundConfigurationPropertiesException: The elements [demo-properties.data[2]] were left unbound.
	at org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler.checkNoUnboundElements(NoUnboundElementsBindHandler.java:88) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler.onFinish(NoUnboundElementsBindHandler.java:73) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.bind.Binder.handleBindResult(Binder.java:235) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:222) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
	... 47 common frames omitted

The bug does only appear when the list in application-test.yml is SMALLER than the list in application.yml.

Regards,
Manuel

@mschallar mschallar changed the title binding Binding on ConfigurationProperties does Mar 22, 2019
@mschallar mschallar changed the title Binding on ConfigurationProperties does Binding on ConfigurationProperties Mar 22, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 22, 2019
@mschallar mschallar changed the title Binding on ConfigurationProperties Binding on ConfigurationProperties: "The elements <...> were left unbound" Mar 22, 2019
@snicoll
Copy link
Member

snicoll commented Mar 22, 2019

Thanks for the sample, that is very useful.

We've tighten the mechanism to merge complex types, see the documentation.

I am not sure if we intended to throw an exception if you combine that with ignoreUnknownFields. If I add a string6 in the test profile, the exception goes away as the full list has been replaced. This shouldn't be necessary IMO.

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Mar 22, 2019
@mbhave
Copy link
Contributor

mbhave commented Mar 22, 2019

I think it's a bug and we shouldn't throw an exception since the list is completely overridden.

@rhamedy
Copy link
Contributor

rhamedy commented Mar 23, 2019

I would be happy to work on this issue should the team decide that it should be fixed 🙂

@snicoll snicoll added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Mar 25, 2019
@snicoll snicoll added this to the 2.1.x milestone Mar 25, 2019
@mbhave
Copy link
Contributor

mbhave commented Mar 25, 2019

Thanks for the offer @rhamedy but I'm already looking into this.

@mbhave mbhave self-assigned this Mar 25, 2019
@mbhave mbhave changed the title Binding on ConfigurationProperties: "The elements <...> were left unbound" Binding to collection fails with unbound elements error if collection overridden in another property source Mar 25, 2019
@mbhave mbhave modified the milestones: 2.1.x, 2.1.4 Mar 25, 2019
@mbhave mbhave closed this as completed in 91c1fc3 Mar 25, 2019
@anatoliy-balakirev

This comment has been minimized.

@snicoll

This comment has been minimized.

@anatoliy-balakirev

This comment has been minimized.

@snicoll

This comment has been minimized.

@snicoll

This comment has been minimized.

@anatoliy-balakirev

This comment has been minimized.

@mbhave

This comment has been minimized.

@anatoliy-balakirev

This comment has been minimized.

@anatoliy-balakirev

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants