Skip to content

signals-clause #58

Description

@wadoon

In the current state, JML ref manual states for the signals clause:

//@ signals (RuntimeException e) ... e ... ;
//@ signals (RuntimeException) ... \exception ... ;

  1. I would like to re-align this to the catch-clauses. In particular, I want to allow multiple exceptions like in try { ... } catch(E1 | E2 e) { }.

    Therefore, I suggest:

    //@ signals (E1 | ... | En  e) <expr>;
    

    The type of e is the union of each type E1 to En as defined by JLS. Also note, that E1 to En have to be disjoint in catch-clauses.

    Concrete example:

    //@ signals (IllegalAccessException | IllegalStateException  e) !e.getMessage().isBlank() ;
    
  2. I propose to make the exception variable mandatory, thus do drop the second line in the current description of the ref manual.

    For me, it seems to be a complicated special case. If anyone does not want to assign a name, they can use _ as an identifier to signal this circumstance.

    This change would not affect \exception.

  3. I have a question:

    Assuming multiple signals clauses, do their exception type need to be disjoint?

    Example:

    //@ signals (IllegalStateException e) f1(e);
    //@ signals (RuntimeException e) f1(e);
    //@ signals (Exception e) f1(e);
    

    Note, that IllegalStateException <: RuntimeException <: Exception <: Throwable.

    This is legal for catch clauses. Java's semantics define that the first catch matching catch-block is executed.

    If we allow this for JML contracts, what are the semantics?

    • First/Java semantics: Only the first signals clause needs to be adhered to in the exceptional case.

      This makes the order of clauses important; I think that is currently not the case.

    • All semantics: Every matching signals-clause must adhere in exceptional cases.

      Under these semantics, we can normalize a given set of signals-clauses to one clause. The given example would become:

      //@ signals (Throwable t) 
             (t instanceof IllegalStateException t1 ==> f1(t1)) &&
             (t instanceof RuntimeException t2 ==> f2(t2)) &&
             (t instanceof RuntimeException t3 ==> f3(t3));
      

Side note: The pattern expression in Java makes the following expression well-typed:

x instanceof String s && s.isBlank()

Do we have defined that this is also well-typed for some JML-operators (in particular, the implication?):

x instanceof String s ==> s.isBlank()

This is not so obvious in the normal form: !(x instanceof String s) || s.isBlank().

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