Skip to content

False error: in main, an early return on the args array makes a later state-refined call report "Variable 'args' could not be found" #465

Open

Description

@CatarinaGamboa

Summary

In a method named main, an early return guarded by the array parameter's length makes a later call with a @StateRefinement fail with Not Found Error: Variable 'xs' could not be found. The same body in a method with any other name verifies.

Minimal reproducer

ZipFileRefinements.java:

import java.util.zip.ZipFile;
import liquidjava.specification.*;

@ExternalRefinementsFor("java.util.zip.ZipFile")
@StateSet({"open", "closed"})
public interface ZipFileRefinements {
    @StateRefinement(to = "open(this)")
    void ZipFile(String name);

    @StateRefinement(from = "open(this)", to = "closed(this)")
    void close();
}

Client.java:

import java.util.zip.ZipFile;

public class Client {
    public static void main(String[] xs) throws java.io.IOException {
        if (xs.length < 1) {
            return;
        }
        ZipFile z = new ZipFile("a.zip");
        z.close();   // Not Found Error: Variable 'xs' could not be found
    }
}

Expected: Correct! Passed Verification.

What changes the result (all with the spec above):

variant result
as above Variable 'xs' could not be found at z.close()
static void main(String[] xs) (not public) same error
renamed to public static void f(String[] xs) passes
no early return (if (...) System.out.println(...)) passes
the return branch removed, or z.close() removed passes
no spec passes

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

Why it matters: real code

A command-line unzip tool (plasma-umass/doppio, classes/util/Unzip.java, MIT):

public static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("Usage: Unzip zipfile prefix");
        return;
    }
    ...
    ZipFile zipFile = new ZipFile(args[0]);
    ...
    zipFile.close();

Checking a usage message and returning at the top of main is common in CLI tools, so any spec'd class used afterwards in main hits this.

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

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions