Skip to content

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

Description

@lynae99

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions