java:S1075 ignore constants used as default

Then tell us:

  • What language is this for? → JAVA
  • Which rule? → java:S1075
  • Why do you believe it’s a false-positive/false-negative? → It is hard coded but not used as part of a uri, it is more like a default or fallback
  • Are you using
    • SonarCloud? → Yes
    • SonarLint - which IDE/version? → IntelliJ 2024.1.3, Sonar Plugin 10.11.1.79663
      • in connected mode with SonarQube or SonarCloud? → Connect with Sonar Cloud
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
    public static final String DEFAULT_EXAMPLE_PATH = "/a-great/path/for-this-example";
    @Value("${url.example-app.path.the-great-one:" + DEFAULT_EXAMPLE_PATH  + "}")
    private String greatExamplePath;

In my Opinion when a URI-Constant is just used as part of @Value default then this should not be raised.

Hi Nico,
I didn’t find a logic related to the constant usage in the rule’s implementation.
Looking at your example, I think the rule should be changed to take into account the constant usage in order to reduce the number of false positives.
So I created this ticket: [SONARJAVA-5149] - Jira
Thank you for your feedback.

Wow thank you very much :100: