False error: a known state 'a or b' is refused by a method allowed from a and from b (one @StateRefinement per state)

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

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

Start by running the minimal Java reproducer in the issue and inspect the verifier’s state refinement checks, especially how it handles methods with multiple from alternatives against a disjunction. Confirm the reported failure and compare it with the single-alternative workaround. Done means the verifier accepts calls allowed in each possible state while still rejecting calls from states the method does not allow.

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

描述

bug

Impact: after any branch that leaves an object in one of two states (if, try/catch, try/finally), a method that is allowed in both states is refused, if its spec lists one @StateRefinement per state. The error message itself shows that the required state holds. This hits the most common resource idioms: close() in finally, and a timed-out accept() in try/catch.

Minimal reproducer

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

@StateSet({"open", "closed"})
class Res {
    @StateRefinement(to = "open(this)")
    public Res() {}

    @StateRefinement(from = "open(this)", to = "closed(this)")
    @StateRefinement(from = "closed(this)")
    public void close() {}
}

public class Repro {
    static void use(boolean early) {
        Res r = new Res();
        if (early) r.close();
        r.close();          // r is open or closed here; close() is allowed in both
    }
}

Expected: Correct! Passed Verification.

Actual (main @ f7f366c, and 1a506fe):

State Refinement Error: found early ? closed(r) : open(r) but expected open(r) || closed(r)

early ? closed(r) : open(r) implies open(r) || closed(r). It looks as if each from= alternative is checked on its own against the disjunction, and neither alone is implied.

Workaround (and a hint at the fix). Writing the same method as one from-less alternative, @StateRefinement(to = "closed(this)"), verifies. We now generate idempotent close() that way. But it only works when the method is allowed in every state. ServerSocket's accept() is allowed from bound and from accepted but not from unbound, and the same problem comes back with no workaround.

Real-world scenarios

  1. close() on the normal path and again in finally (java.io.BufferedReader, where close() is idempotent), with close() specified per state:

    BufferedReader r = new BufferedReader(new StringReader("a\nb"));
    try {
        r.readLine();
        r.close();
    } finally {
        r.close();          // refused: open || closed
    }
    
  2. An accept with a timeout (java.net.ServerSocket, with accept() allowed from="bound(this)", to="accepted(this)" and from="accepted(this)"). This is the standard way to accept with a timeout:

    ServerSocket s = new ServerSocket(0);
    s.setSoTimeout(50);
    try {
        s.accept();
    } catch (IOException timeout) {
        System.out.println("timed out");
    }
    s.close();              // refused: bound || accepted
    

    An earlier comparison on an older verifier (321a7321 / 0.0.33) reported both programs as accepted with this spec. I haven't re-run that version. On 1a506fe and f7f366c both are refused. Rewriting accept() as one alternative from = "bound(this) || accepted(this)" moves the error to close(), which is also written one alternative per state.

主要語言
Java
星號
73
分支
38
平均合併
12 小時 32 分鐘
30 天內合併 PR
45

環境準備

從這裡開始

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

liquid-java/liquidjava 的其他 Issue

查看 liquid-java/liquidjava 的全部 Issue

相似的 Issue

更多 Java Issue

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

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