facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.8k stars 2k forks source link

false positive resource of type `javax.net.ssl.HttpsURLConnection` #1759

Open SolomonSun2010 opened 1 year ago

SolomonSun2010 commented 1 year ago

Please make sure your issue is not addressed in the FAQ.

Please include the following information:

javacheck/HttpURLConnectionTest.java:18: error: Resource Leak resource of type javax.net.ssl.HttpsURLConnection acquired by call to openConnection() at line 13 is not released after line 18.

  1. return conn;
  2. } else {
  3.         System.out.println("url open connection is not HttpURLConnection");
  4. // Logger.error(TAG, "url open connection is not HttpURLConnection");
  5. throw new IOException();

Found 1 issue Issue Type(ISSUED_TYPE_ID): # Resource Leak(RESOURCE_LEAK): 1

// import androidx.annotation.NonNull;

import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection;

class HttpURLConnectionTest {

protected HttpURLConnection connect_FP(URL url) throws IOException {
    URLConnection urlConn = url.openConnection();
    if (urlConn instanceof HttpURLConnection) {
        HttpURLConnection conn = (HttpURLConnection) urlConn;
        return conn;
    } else {
        System.out.println("url open connection is not HttpURLConnection");
        // Logger.error(TAG, "url open connection is not HttpURLConnection");
        throw new IOException();
    }
}

}

yunshouhu commented 1 year ago

I also encountered the same problem

SolomonSun2010 commented 1 year ago

I also encountered the same problem

okay, nice to meet you here.