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

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

Maintainer thường phản hồi trong vòng 1 ngày

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
56/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
testing-qa

Hướng nghiên cứu

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.

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

Mô tả

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).

Ngôn ngữ chính
Java
Star
73
Fork
38
Merge trung bình
12 giờ 32 phút
Pull request đã merge (30 ngày)
45

Chuẩn bị môi trường

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 liquid-java/liquidjava

Tất cả issue của liquid-java/liquidjava

Issue tương tự

Thêm issue về Java

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.