Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

False Positive: CloseReader.ql reports resources that are either transferred to another owner or closed by a wrapper.

Đang mở
#21,530 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
java
Lĩnh vực
devtools, security

Hướng nghiên cứu

Đọc Likely Bugs/Resource Leaks/CloseReader.ql và so sánh hành vi của nó với NegCase3.java và NegCase7.java, sau đó chạy các bài kiểm thử query bị ảnh hưởng. Hoàn thành khi hai dòng được báo cáo này không còn bị đánh dấu, trong khi các trường hợp Reader, InputStream và ZipFile thực sự chưa được đóng vẫn tiếp tục được phát hiện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

question

Version
codeql 2.24.3

Checker

  • Checker id: Likely Bugs/Resource Leaks/CloseReader.ql
  • Checker description: This checker detects instances of Reader, InputStream, or ZipFile objects that are created but not guaranteed to be closed on method exit, potentially causing resource leaks.

Description of the false positive

Neither sample is a straightforward leak.

In NegCase3.java, the FileInputStream is immediately wrapped by a type whose close() implementation delegates to the underlying stream. In NegCase7.java, the stream is passed into another object and stored there, which is an ownership-transfer pattern rather than a local leak.

Affected test cases

NegCase3.java

The wrapper is the owner. Reporting the inner FileInputStream as leaked means the query is not trusting a wrapper that clearly forwards close().

NegCase7.java

The stream escapes through field = new Outer(is). That may or may not be a great API design, but it is not the same as dropping a local resource on the floor.

Reproduction code

NegCase3.java
// A FileInputStream wrapped in a custom closeable with empty close should not be flagged as a leak.
package scensct.core.neg;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

public class NegCase3 {
    // Custom wrapper with empty close method.
    static class NoCloseWrapper extends InputStream {
        private final InputStream inner;
        NoCloseWrapper(InputStream in) { this.inner = in; }
        @Override public int read() throws IOException { return inner.read(); }
        @Override public void close() throws IOException { inner.close(); } // Now delegates closing.
    }

    public void test() throws IOException {
        // Scenario 3: Transitive closeable parent satisfies noNeedToClose.
        new NoCloseWrapper(new FileInputStream("test.txt")); // Inner resource managed by wrapper. // [REPORTED LINE]
    }
}
NegCase7.java
// A FileInputStream passed to a locally initialized outer constructor and escaping should not be flagged as a leak.
package scensct.core.neg;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;

public class NegCase7 {
    static class Outer {
        private final InputStream inner;
        Outer(InputStream in) { this.inner = in; } // No exceptions declared.
    }

    private Outer field;

    public void test() throws IOException {
        // Scenario 7: Resource not assigned, passed to constructor, escapes via field.
        InputStream is = new FileInputStream("test.txt"); // [REPORTED LINE]
        field = new Outer(is); // Resource escapes, no leak.
    }
}

Cause analysis

These results suggest two over-approximations in Likely Bugs/Resource Leaks/CloseReader.ql.

First, the query is not reliably recognizing wrapper classes that take responsibility for the underlying resource. Second, it is treating ownership transfer as if it were equivalent to local abandonment. Both behaviors inflate the result set with cases that developers will not read as direct leaks in the current method.

Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 16 giờ
Pull request đã merge (30 ngày)
143

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/codeql

Tất cả issue của github/codeql

Issue tương tự

Thêm issue về DevTools

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.