Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

False error: a local declared inside try is "not found" at a call in finally

未关闭
#406 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
20/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
compilers

调研方向

Start by reproducing the report: save the Repro class from the issue and run LiquidJava on it to see the Not Found Error at input.close() in the finally. The cause is that the state of input recorded at the end of the try still mentions the block-local length, which is out of scope when the finally checks close(). Done means the repro passes verification and the change does not break the existing tests.

由索引模型根据 Issue 内容生成。

描述

bug

With the Barista BufferedInputStream spec (read() returns _ >= -1; read(byte[], int, int) refines its length):

import java.io.*;

public class Repro {
    static int load(InputStream raw, boolean known) throws IOException {
        BufferedInputStream input = new BufferedInputStream(raw);
        try {
            int cost = 0;
            if (known) {
                int length = input.read();
                if (length >= 0) {
                    byte[] nonce = new byte[length];
                    input.read(nonce, 0, length);
                }
            }
            return cost;
        } finally {
            input.close();
        }
    }
}

On main 1c6807be (and 321a7321):

Not Found Error: Variable 'length' could not be found
  input.close();   (in the finally)

length is a block-local of the try; the state of input recorded in the try (after read(nonce, 0, length)) mentions it, and when the finally checks close() against that state, length is out of scope. Expected: Correct! Passed Verification. (out-of-scope locals should be eliminated or kept as fresh variables when the state flows into the finally / after the block).

Found in a real-code example (secrets-for-android FileUtils, a length-prefixed read in try/finally). Since #366 the example's earlier workaround (guarding with a block instead of an early return) no longer avoids it.

主要语言
Java
星标
69
派生
36
平均合并
2 天 1 小时
30 天内合并 PR
35

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。