FALSE NEGATIVE: `java:S2695` misses a zero ResultSet index derived from a loop

Hi, I found a false negative in SonarQube 26.7.0 with sonar-java 8.34 when the first loop iteration passes index zero to a ResultSet getter.

Affected tool

SonarQube 26.7.0.124771; sonar-java 8.34 (build 44906)

Affected checker

SonarQube java:S2695

Minimal reproducer

import java.sql.ResultSet;

class SpotbugsSonarqubeS2695DerivedZeroIndex {
  String first(ResultSet result) throws Exception {
    for (int index = 0; index < 2; index++) return result.getString(index);
    return "";
  }
}

Reproduction command

sonar-scanner --version
sonar-scanner -Dsonar.projectKey=spotbugs-sonarqube-reproducer -Dsonar.sources=spotbugs-sonarqube-s2695-fn-derived-zero-index.java -Dsonar.host.url="$SONAR_HOST_URL" -Dsonar.token="$SONAR_TOKEN"

Current behavior

SonarQube produces no java:S2695 diagnostic.

Expected behavior

SonarQube should report java:S2695 at line 5 because the first call uses column index 0.

Hello @marktiwnzhao,

Thanks for your report. I’ve created JIRA ticket to solve this issue.