Skip to content

Configuration processor does not handle generics #15850

@garyrussell

Description

@garyrussell

Given

@ConfigurationProperties("foo.bar")
public class GenericProperties extends AbstractPropeties<Foo> {

}

and

public class AbstractPropeties<T> {

	private Map<String, T> props;

	public Map<String, T> getProps() {
		return props;
	}

	public void setProps(Map<String, T> props) {
		this.props = props;
	}

}

The generated metadata is

{
  "groups": [
    {
      "name": "foo.bar",
      "type": "com.example.GenericProperties",
      "sourceType": "com.example.GenericProperties"
    }
  ],
  "properties": [
    {
      "name": "foo.bar.props",
      "type": "java.util.Map<java.lang.String,T>",
      "sourceType": "com.example.GenericProperties"
    }
  ],
  "hints": []
}

Should be

{
  "groups": [
    {
      "name": "foo.bar",
      "type": "com.example.GenericProperties",
      "sourceType": "com.example.GenericProperties"
    }
  ],
  "properties": [
    {
      "name": "foo.bar.props",
      "type": "java.util.Map<java.lang.String,com.example.Foo>",
      "sourceType": "com.example.GenericProperties"
    }
  ],
  "hints": []
}

The generator should be able to determine the generic type.

Per Kris De Volder in Slack

Generics is complex, so I'm never surprised if it breaks stuff like this. But in my opinion it should be considered a bug. The method may be inherted from a generic superclass (or overridden). But from the subclass point of view we know that type 'T' is really 'RabbitBindingProperties'. So its reasonable to expect the Spring boot annotation processor to treat 'T' as if it is equal to 'RabbitBindingProperties' in that context.
So I think you should raise a bug against spring boot configuration processor.

See spring-cloud/spring-cloud-stream#1601

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions