I have a null check on a FileInputStream object and SonarQube says that on the first line of this block:
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException ioe) {}
}
only (and I quote): "Covered by tests (3 of 4 conditions)"
How in this world can there be 4 conditions? I can only see 2 conditions: either the object is null or not. Can anyone post those other 2 conditions? I use java 8. Is there a way to please Sonar? A workaround? Anything.
Update: I removed the if statement and replaced the whole if block with
org.apache.commons.io.IOUtils.closeQuietly(fileInputStream);
which checks for null and makes Sonar happy.
As of Sonar 7.0 and Jacoco 6.5 it is now possible to use try with resources as a more elegant solution than
org.apache.commons.io.IOUtils.closeQuietly(fileInputStream);