Please provide
- Operating system: Amazon Linux 2 - aarch64
- SonarLint plugin version: v3.20.2
- Programming language you’re coding in: Java
- Is connected mode used: No
And a thorough description of the problem / question:
I am using Apache Http Components’ HttpClient 5.2.x in my code. Specifically this method. There are a few variants of this method which are @Deprecated
but not this one. Yet, SonarLint reports it as deprecated in VSCode. If I use the “go to definition” feature of VSCode, it takes me to the correct function definition (the one that I am using, that is not deprecated). So, the project seems to be set up correctly.
Rule Id - java:S1874
Sample code -
MyRequest.java
package com.mypackage;
import com.mypackage.BaseResponse;
import java.net.URI;
import lombok.AllArgsConstructor;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.cookie.BasicCookieStore;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@AllArgsConstructor
public class MyRequest extends BaseRequest {
private CloseableHttpClient httpClient;
private URI requestURI;
public BaseResonse executeRequest() throws Exception {
HttpGet request = new HttpGet(requestURI);
HttpClientContext localContext = HttpClientContext.create();
localContext.setCookieStore(new BasicCookieStore());
return httpClient.execute(
request,
localContext,
(ClassicHttpResponse _response) ->
new BaseResponse(_response.getCode(), EntityUtils.toString(_response.getEntity()))
);
}
}
BaseResponse.java
package com.mypackage;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class BaseResponse {
private int httpStatusCode;
private String responseString;
}
Error message -
Remove this use of “execute”; it is deprecated.sonarlint(java:S1874)