spring-tools: "Unknown property" marker is created when there is a setter but no getter

STS for Eclipse Version: 4.21.0.RELEASE

In application config YAML files, STS will mark a property as unknown (error or warning depending on how I have STS configured) even if there is a setter for that property in the corresponding Java @ConfigurationProperties class. If I have both getter and setter, the error/warning goes away.

For example, given this class:

@ConfigurationProperties(prefix = "foo")
public class MyProperties {
	private String envName;
	public void setEnvName(String name) { };
}

and this YAML:

foo:
  envName: bar

STS puts an error/warning marker in the YAML saying envName is an unknown property.

If I add this getter to MyProperties:

	public String getEnvName() { return ""; }

Then the YAML error/warning goes away.

It seems that a property with only a setter shouldn’t trigger an error/warning, since all that matters to Spring is that it can know where to put the value from the YAML. Before anyone starts quoting the Java Beans spec to me, I know that a property with no getter is not a strict Java Beans property. Practically speaking, however, Spring doesn’t care; it still correctly sets the YAML value into the config object. So STS is not agreeing with Spring’s own runtime behavior.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

  • make sure users can use custom self-written metadata descriptions to override or enhance the generated metadata, so that users can educate the tooling to accept specific properties. Some of this is already in place, but we need to make sure that this is a smooth and straight forward experience.

I was able to manually edit the additional-spring-configuration-metadata.json file that I generated with the QuickFix (from the root of my type-safe config POJO. The original generated file was like this:

{"properties": [
  {
    "name": "foo",
    "type": "com.foo.MyAppProperties",
    "description": "Properties to configure the application"
  }
]}

That satisfies STS for most properties in MyAppProperties, but not the ones without getters.

I edited it to add specifically the properties that don’t have getters, like this:

{"properties": [
  {
    "name": "foo",
    "type": "com.foo.MyAppProperties",
    "description": "Properties to configure the application"
  },
  {
    "name": "foo.envName",
    "type": "java.lang.String",
    "description": "Custom property that has no direct getter."
  }
 ]}

With that, STS no longer generates a warning for the property envName that has no getter.