Skip to content

Crash: "Sorts Int and Bool are incompatible" when a JDK method's result is passed to a parameter refined in an external spec #451

Closed

Description

@CatarinaGamboa

Impact: passing an int returned by an unspecified JDK method to a parameter refined in an external spec crashes the verifier with an internal sort error. The expected outcome is a refinement error, or an accept. This is the everyday way to connect a socket in tests and tools: new Socket(host, server.getLocalPort()).

Minimal reproducer (an external spec and a client, in one directory)

// SocketRefinements.java
@ExternalRefinementsFor("java.net.Socket")
public interface SocketRefinements {
    void Socket(InetAddress address, @Refinement("_ >= 0 && _ <= 65535") int port);
}

// Client.java
public class Client {
    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(0);
        Socket s = new Socket(InetAddress.getLoopbackAddress(), server.getLocalPort());
        server.close();
    }
}

Expected: a refinement error, because server.getLocalPort() can't be proved in range. The same shape in-source gives one: port³ == port¹ is not a subtype of port³ >= 0 && port³ <= 65535.

Actual (main @ f7f366c, and 1a506fe):

Error: Sorts Int and Bool are incompatible

With a literal port (8080) the program verifies.

Real-world scenario. I found this while scoring java.net.Socket specs on JVM-checked probes. Every probe that connects to a local test server (new ServerSocket(0), then new Socket(loopback, server.getLocalPort())) crashes the verifier. That happens both with co-specification's generated spec and with the specs-v2 Socket spec, which refines ports the same way (Port(int x) { x >= 0 && x <= 65535 }).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    studyNeeded before the error-message user study

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions