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

Confusing error message if property not found when ConstructorBinding is used #18704

Closed
jnizet opened this issue Oct 23, 2019 · 1 comment
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@jnizet
Copy link
Contributor

jnizet commented Oct 23, 2019

When executing the following application:

package com.example.demo

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding
import org.springframework.boot.runApplication

@SpringBootApplication
class BadErrorMessageApplication

@ConfigurationProperties(prefix = "test")
@ConstructorBinding
class MyProperties(val foo: String, val bar: String)

fun main(args: Array<String>) {
    runApplication<BadErrorMessageApplication>(*args)
}

with the following application.yml file:

test:
  # foo: hello
  bar: world

where foo is intentionally commented out, the application fails to start (as expected), but with a confusing error message:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'test' to com.example.demo.MyProperties:

    Property: test.bar
    Value: world
    Origin: class path resource [application.yml]:3:8
    Reason: Parameter specified as non-null is null: method com.example.demo.MyProperties.<init>, parameter foo

Action:

Update your application's configuration

The Reason part is correct: the parameter foo is missing. But the Property is incorrect: what is missing is the property foo, not the property bar. And the Value: world is irrelevant to the problem, too.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 23, 2019
@snicoll
Copy link
Member

snicoll commented Oct 23, 2019

I might have been too quick to close #17908. Thanks @jnizet!

@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 23, 2019
@snicoll snicoll added this to the 2.2.x milestone Oct 23, 2019
@mbhave mbhave self-assigned this Oct 24, 2019
@mbhave mbhave modified the milestones: 2.2.x, 2.2.1 Oct 25, 2019
@mbhave mbhave closed this as completed in dec6ee2 Oct 25, 2019
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

4 participants