facebook / facebook/infer

FALSE NEGATIVE: PULSE_RESOURCE_LEAK misses an unclosed stream returned by `Files.newInputStream()`

Open
#2,110 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 `Files.newInputStream()` returns a stream that is used but never closed.

**Affected tool**

`Infer 1.3.0`

**Affected checker**

`Infer PULSE_RESOURCE_LEAK`

**Minimal reproducer**

```java
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

class InferLeakFilesNewInputStream {
void test(Path path) throws IOException {
InputStream stream = Files.newInputStream(path);
stream.read();
}
}
```

**Reproduction command**

```bash
infer --version
infer run --pulse --enable-issue-type PULSE_RESOURCE_LEAK -- javac spotbugs-to-infer-resourceleak-fn-files-new-input-stream.java
```

**Current behavior**

Infer completes successfully but produces no `PULSE_RESOURCE_LEAK` finding.

**Expected behavior**

Infer should report `PULSE_RESOURCE_LEAK` at line 8 because `Files.newInputStream()` returns an `InputStream` that is used but never closed.

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.