Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Soundness: try/catch is checked as if the catch block always runs

未關閉
#364 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
50/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
compilers

研究方向

Locate where the verifier visits try/catch statements (search the visitor/checker for the try-statement case) and compare it with how if/else merges branch states at the join point — the issue says try/catch is currently sequenced instead of merged. Work out how both branches (normal exit from try, entry into catch at an arbitrary point) should be joined, and how the state after the join relates to the state on entry. Done means both reproducers in the issue report errors, the swapped-value case reports correctly, and existing verification tests still pass; add the reproducers as regression tests.

由索引模型根據 Issue 內容生成。

描述

bug

Impact: a real bug passes verification (false negative).

Description

The verifier checks try and catch blocks one after the other, so after a try/catch a variable keeps whatever the catch block last assigned. The path where the try finishes normally is lost. An if/else instead merges both branches after the join, and try/catch should be merged the same way.

Also, an exception can be thrown at any point in the try. The catch block should therefore not assume the try ran to completion, or that it never ran at all.

Minimal reproducer

import liquidjava.specification.ExternalRefinementsFor;
import liquidjava.specification.StateRefinement;
import liquidjava.specification.StateSet;

@ExternalRefinementsFor("java.lang.Throwable")
@StateSet({"withThrowable", "noThrowable"})
interface ThrowableRefinements {
    @StateRefinement(to = "noThrowable(this)")
    void Throwable(String message);

    @StateRefinement(to = "withThrowable(this)")
    void Throwable(String message, Throwable cause);

    @StateRefinement(from = "noThrowable(this)", to = "withThrowable(this)")
    Throwable initCause(Throwable cause);
}

public class Repro {
    static void load() throws Exception { throw new Exception("x"); }

    static void m() {
        Throwable t = new Throwable("start");
        try {
            load();
            t = new Throwable("try", new RuntimeException()); // withThrowable
        } catch (Exception e) {
            t = new Throwable("catch");                       // noThrowable
        }
        t.initCause(new RuntimeException()); // not reported, but t is withThrowable if load() returns
    }
}

Expected: a State Refinement Error on t.initCause(...), because t may be withThrowable.

Actual: Correct! Passed Verification.

Same bug with value refinements

static void m() {
    int y = 0;
    try {
        load();
        y = -5;
    } catch (Exception e) {
        y = 7;
    }
    @Refinement("_ > 0")
    int z = y; // not reported, but y == -5 if load() returns
}

Actual: Correct! Passed Verification. If the values are swapped (5 in the try, -5 in the catch), the error is reported, but as z == -5 is not a subtype of z > 0: only the catch path is considered.

Found while reviewing #362 (catch parameters, #333).

主要語言
Java
星號
67
分支
36
平均合併
2 天 3 小時
30 天內合併 PR
29

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。