S6857 Default value zero length string in SpEL reported as issue

  • What language is this for? *Java
  • Which rule? java:S6857
  • Why do you believe it’s a false-positive/false-negative?
  • using SonarCloud

Here’s an example that is reported by Sonar :

public class TestConfiguration {
    @Value("${anyValue:}")
    private String anyString;
}

This sets the value of anyValue to the anyString variable, and an empty string if anyValue is null.
Documented here : https://www.baeldung.com/spring-value-defaults#string-defaults

Removing the comma fixes the issue, but it also changes the behaviour of the code.

Hello @adambir, thank you for pointing out this missing scenario that [SONARJAVA-4741] - Jira will cover together with other corner cases.

Cheers,
Angelo

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.