Skip to content

Properties in '@ConfigurationProperties' annotated type shouldn't be able to define the same '@Name' #49565

@snicoll

Description

@snicoll

Courtesy of @YannCebron

@ConfigurationProperties("vet")
public class VetConfigProps {

    @Name("aaa")
    private String company;

    @Name("aaa")
    private String name;

    public void setCompany(String company) {
        this.company = company;
    }

    public String getCompany() {
        return company;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

}

The annotation processor completes successfully and generates the following JSON:

{
  "groups": [
    {
      "name": "vet",
      "type": "org.springframework.samples.petclinic.vet.VetConfigProps",
      "sourceType": "org.springframework.samples.petclinic.vet.VetConfigProps"
    }
  ],
  "properties": [
    {
      "name": "vet.aaa",
      "type": "java.lang.String",
      "sourceType": "org.springframework.samples.petclinic.vet.VetConfigProps"
    }
  ],
  "hints": [],
  "ignored": {
    "properties": []
  }
}

At runtime setting vet.aaa binds to the two annotated fields. I believe this should raise an error as two properties have the same ID (which they can't).

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions