URIs should not be hardcoded. Doesn't work for my code

java
sonarqube

(Oliveira) #1

I am hoping to use this rule to avoid hardcode in production projects. Recently, the rule in question did not warn, but the code had a URL encoded.

I tried with sonarqube version 5.6 and also with a local test using the docker image in version 7.6

Code that I am trying to trigger rule.

@SuppressWarnings (“rawtypes”)
protected ResponseEntity postForEntity(URI uri, Object body, Class responseType) {

try {

    ResponseEntity<T> response = restTemplate.postForEntity("http://something:8010/operation/test", body, responseType);

    return response;

} catch (HttpClientErrorException | HttpServerErrorException e) {

    logger.error(e);
    return processErrorResponse(e.getResponseBodyAsString(), e.getStatusCode());

} catch (RestClientException e) {
    logger.error(e);
}

return null;

}