Resources should be closed not warns on new FileInputStream

java
sonarqube

(ori marko) #1

The following java code should create a sonar warning of “Resources should be closed (squid:S2095)”
Because FileInputStream (resource) in created and not closed in code

public static String getMD5Checksum(String filePath) throws Exception {
    File file = new File(filePath);
    FileInputStream fis = new FileInputStream(file);
    return DigestUtils.md5Hex(fis);
}

Notice that if we add fis.read(); it warns OK


(Franck Biellmann) #2

Hello. Can anybody answer? I am very interested by the subject also… Thank you…


(Franck Biellmann) #3

Hello. Can anybody answer? I