java:S6804 false positive for @Value on Resource

Rule java:S6804: "@Value" annotation should inject property or SpEL expression gives a false positive for @Value on Resource. This rule was added with [SONARJAVA-4643] - Jira in Sonar Java version 7.27.0.33463.

This code is valid and should not produce a warning, but Sonar incorrectly flags it:

public class TestComponent {
	@Value("classpath:some.xml")
	private Resource someXml;
}

See https://www.baeldung.com/spring-load-resource-as-string#using-spel

1 Like

Hi @candrews ,

This is indeed an FP. Thank you for reporting it and providing a link to the documentation. We missed it when we worked on the rule.

I have created a ticket about the issue and you can track its progress here. For now, you can mark the issue as an FP.