A false negative about the rule S2115

I found a false negative about the rule S2115, please read the following information:

  • What language is this for?
    • Java
  • Which rule?
    • S2115
  • Why do you believe it’s a false-positive/false-negative?
    • See the following minimized code example, line 8 is equivalent to line 9, but SonarQube reports a warning at line 8, no warnings at line 9. So, this is a false negative bug.
  • Are you using
    • SonarQube Server / Community Build - Latest
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

Minimized Code Example

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Objects;

public class Main {
    public void foo() throws Exception {
        String pwd = "";
        Connection conn1 = DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", pwd); // report a S2115 warning
        Connection conn2 = DriverManager.getConnection("jdbc:derby:memory:myDB;create=true", "login", Objects.requireNonNull(pwd)); // report no warnings
    }
}

Hi R Jerrica,

Thank you for the report! Yes, this is a false negative. I create a ticket, SONARJAVA-5821, to track and resolve this issue.

Cheers,
Tomasz