Variable 'this' could not be found when a ghost-refined method is called on another call's result

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start by tracing how the verifier handles the get(0) call in Client.java when it follows m.get("k"), then compare that path with the local-variable example in the issue. Use the supplied ArrayListRefinements.java and reproducer to locate the handling of receiver ghost refinements. Done when the chained form reports the expected unknown-size refinement error instead of failing to find this.

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

描述

bug

Summary

A method whose parameter refinement mentions the receiver's ghost (index < size(this)) fails with Not Found Error: Variable 'this' could not be found when it is called on another call's result, as in m.get("k").get(0). With a local variable in between, the verifier reports the expected refinement error (the receiver's size is unknown), so only the chained form breaks.

Minimal reproducer

ArrayListRefinements.java:

import liquidjava.specification.ExternalRefinementsFor;
import liquidjava.specification.Ghost;
import liquidjava.specification.Refinement;
import liquidjava.specification.StateRefinement;

@ExternalRefinementsFor("java.util.ArrayList")
@Ghost("int size")
public interface ArrayListRefinements<E> {
    @StateRefinement(to = "size(this) == 0")
    void ArrayList();

    @StateRefinement(to = "size(this) == size(old(this)) + 1")
    boolean add(E e);

    E get(@Refinement("_ >= 0 && _ < size(this)") int index);

    @Refinement("_ == size(this) && _ >= 0")
    int size();
}

Client.java:

import java.util.ArrayList;
import java.util.HashMap;

public class Client {
    public static void main(String[] args) {
        HashMap<String, ArrayList<String>> m = new HashMap<>();
        ArrayList<String> l = new ArrayList<>();
        l.add("a");
        m.put("k", l);
        String s = m.get("k").get(0);   // Not Found Error: Variable 'this' could not be found
    }
}

Expected: a refinement error at get(0) (the list comes from HashMap.get, so its size is unknown), the same one the verifier gives for ArrayList<String> x = m.get("k"); x.get(0);: index == 0 is not a subtype of index >= 0 && index < size(x).

Seen on 1a506fe and main at 19991d3.

Why it matters: real code

Chained reads from a map of lists are common. One of five mined GitHub methods using ArrayList does this: Minimum-Vertex-Cover MVC.readGraph, while (lineNum <= Integer.parseInt(result.get("0").get(0))). The error stops verification of the whole method, and its message points at this, which the user never wrote.

Found while checking mined client code against JDK specs (liquid-java/co-specification, verifier probe V38).

主要语言
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 摘要。