Skip to content

Do not generate metadata for non-static nested class that are not initialized #50133

@nikolamicic21

Description

@nikolamicic21

Having the following configuration properties class defined:

@ConfigurationProperties("demo")
public class MyProps {
    private InnerFoo innerFoo;

    public class InnerFoo {
        private String bar;

        public String getBar() {
            return bar;
        }

        public void setBar(String bar) {
            this.bar = bar;
        }
    }

    public InnerFoo getInnerFoo() {
        return innerFoo;
    }

    public void setInnerFoo(InnerFoo innerFoo) {
        this.innerFoo = innerFoo;
    }
}

Annotation processor generates the following spring-configuration-metadata.json file:

{
  "groups": [
    {
      "name": "demo",
      "type": "com.example.demo.props.MyProps",
      "sourceType": "com.example.demo.props.MyProps"
    },
    {
      "name": "demo.inner-foo",
      "type": "com.example.demo.props.MyProps$InnerFoo",
      "sourceType": "com.example.demo.props.MyProps",
      "sourceMethod": "getInnerFoo()"
    }
  ],
  "properties": [
    {
      "name": "demo.inner-foo.bar",
      "type": "java.lang.String",
      "sourceType": "com.example.demo.props.MyProps$InnerFoo"
    }
  ],
  "hints": [],
  "ignored": {
    "properties": []
  }
}

Defined property demo.inner-foo.bar cannot be resolved at runtime. In some cases the demo.innerFoo field being null, and in other with the following exception:

Failed to bind properties under 'demo.inner-foo' to com.example.demo.props.MyProps$InnerFoo:

    Reason: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'this$0' is not valid

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions