Hi, I found a false negative in Infer 1.3.0 when the second allocation can throw before control enters the try block, leaving the first stream and channel unclosed.
Affected checker
Infer PULSE_RESOURCE_LEAK
Minimal reproducer
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
class InferLeakNestedChannelAllocation {
void test(File source, File destination) throws IOException {
FileChannel input = new FileInputStream(source).getChannel();
FileChannel output = new FileOutputStream(destination).getChannel();
try {
input.transferTo(0, input.size(), output);
} finally {
input.close();
output.close();
}
}
}
Reproduction command
infer --version
infer run --pulse --enable-issue-type PULSE_RESOURCE_LEAK -- javac infer-resourceleak-fn-nested-channel-allocation.java
Current behavior
Infer completes successfully but produces no PULSE_RESOURCE_LEAK finding.
Expected behavior
Infer should report PULSE_RESOURCE_LEAK at line 9 because the second allocation can throw before control enters the try block, leaving the first stream and its associated channel unclosed. As a control, the equivalent pattern using FileInputStream and FileOutputStream directly is correctly reported. The false negative appears when the first resource is accessed through its associated FileChannel obtained via getChannel().
Hi, I found a false negative in Infer 1.3.0 when the second allocation can throw before control enters the try block, leaving the first stream and channel unclosed.
Affected checker
Infer PULSE_RESOURCE_LEAKMinimal reproducer
Reproduction command
Current behavior
Infer completes successfully but produces no
PULSE_RESOURCE_LEAKfinding.Expected behavior
Infer should report
PULSE_RESOURCE_LEAKat line 9 because the second allocation can throw before control enters thetryblock, leaving the first stream and its associated channel unclosed. As a control, the equivalent pattern usingFileInputStreamandFileOutputStreamdirectly is correctly reported. The false negative appears when the first resource is accessed through its associatedFileChannelobtained viagetChannel().