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

Aperta
#466 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Java
Stelle
73
Fork
38
Merge medio
12h 32m
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di liquid-java/liquidjava

Tutte le issue di liquid-java/liquidjava

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.