Can CloseableHttpResponse can be null if called inside a try with resource

39 views Asked by At

I have a code block like the one below, where I call the CloseableHttpClient.execute and read the response as CloseableHttpResponse in a try with resource block. I wanted to check the response status using getStatusLine() and had some questions.

CloseableHttpClient someCloseableHttpClient;
try (CloseableHttpResponse response = 
 someCloseableHttpClient.execute(request)) {
   if(response==null || response.getStatusLine() == null){
      log.info("Is this possible?");
   } else {
      dosometing(response);
   }
}

I feel that the null check is unnecessary for both the response and getStatusLine(). Can someone help confirm that they cannot be null

0

There are 0 answers