spring-projects / spring-projects/spring-tools
"Unknown property" marker is created when there is a setter but no getter
@BoykoAlex is already working on this.
Since Feb 5, 2024.
- Dominant language
- Java
- Stars
- 983
- Forks
- 240
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 7
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.