- What language is this for? java
- Which rule? S1144
- Why do you believe it’s a false-positive/false-negative? false-positive
- Are you using
- SonarCloud?
- SonarQube - which version? sonarqube:10.6.0-community
- SonarLint - which IDE/version?
- in connected mode with SonarQube or SonarCloud?
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
I simplify my file:
package tech.jhipster.cassandraapp.shared.authentication.infrastructure.primary;
import io.cucumber.java.en.Given;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.ClientHttpRequestInterceptor;
public class AuthenticationSteps {
@Given("I am logged in as {string}")
public void authenticateUser(String username) {
interceptorsWithAuthentication();
}
private List<ClientHttpRequestInterceptor> interceptorsWithAuthentication() {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
User userToAuthenticate = new User();
interceptors.add((request, body, execution) -> {
request.getHeaders().set(HttpHeaders.AUTHORIZATION, "Bearer " + userToAuthenticate.token());
return execution.execute(request, body);
});
return interceptors;
}
private static class User {
public User() {}
private String token() {
return "123456";
}
}
}
Error on line private String token() {
whereas token
function is used on line request.getHeaders().set(HttpHeaders.AUTHORIZATION, "Bearer " + userToAuthenticate.token());