Spec predicates cannot mention null: "Variable 'null' could not be found"

オープン
#466 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
compilers

調査の方向性

Start by running the DatagramSocketRefinements.java and Client.java reproducer to confirm that null in the predicate triggers the reported error. Then trace how the spec predicate is parsed and checked; the issue does not name those implementation files. Done means the reproducer verifies successfully and reports Correct! Passed Verification.

索引モデルが issue の本文から書いたものです。

説明

enhancement

Summary

A spec predicate cannot mention null: bindaddr == null ? ... : ... gives Not Found Error: Variable 'null' could not be found. So a spec cannot say what the JDK does when a parameter is null, even where that is the documented way to choose a state.

Minimal reproducer

DatagramSocketRefinements.java:

import java.net.SocketAddress;
import liquidjava.specification.*;

@ExternalRefinementsFor("java.net.DatagramSocket")
@StateSet({"unbound", "bound"})
public interface DatagramSocketRefinements {
    @StateRefinement(to = "bindaddr == null ? unbound(this) : bound(this)")
    void DatagramSocket(SocketAddress bindaddr);

    @StateRefinement(from = "unbound(this)", to = "bound(this)")
    void bind(SocketAddress addr);
}

Client.java:

import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class Client {
    public static void main(String[] args) throws Exception {
        DatagramSocket s = new DatagramSocket(null);   // Variable 'null' could not be found
        s.setReuseAddress(true);
        s.bind(new InetSocketAddress(0));
        s.close();
    }
}

Expected: Correct! Passed Verification. On the JVM this runs: DatagramSocket(SocketAddress) says "if the address is null, creates an unbound socket", so that options such as setReuseAddress can be set before binding.

Seen on 1a506fe, f7f366c and main at 19991d3.

Why it matters: real code

Without null in predicates the spec has to pick one state for the constructor. Choosing bound (what every other constructor does) rejects the documented idiom above, which real UDP code uses. Two of five mined GitHub methods using DatagramSocket do exactly this: create with null, then bind(new InetSocketAddress(IP, port)) (e.g. Padawan-Transport-Protocol-PTP Sender.createSocket). Choosing unbound instead lets bind on an already-bound socket through, which throws SocketException on the JVM.

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

主要言語
Java
スター
73
フォーク
38
平均マージ
12時間 32分
マージ済み PR(30日)
45

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

liquid-java/liquidjava のほかの issue

liquid-java/liquidjava の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。