facebook / facebook/infer

FALSE NEGATIVE: PULSE_RESOURCE_LEAK misses nested stream allocations before a channel try block

Open
#2,103 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
OCaml
Stars
15.7k
Forks
2.1k
Avg merge
19h 36m
Merged PRs (30d)
13

Description

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**

```java
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**

```bash
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()`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.