Skip to content

Have immutable flag to allow for returning unmodifiable collections in java.util.Collections #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: development
Choose a base branch
from

Conversation

slyubomirsky
Copy link
Contributor

This might require some careful thought. From what I understand, there are plans to rework OpenJML collections on a larger scale, so perhaps this is not so disruptive a change.

I wonder if a better (less coupled and cluttered) approach would be to simply have model classes implementing List, Collection, etc., that throw UnsupportedOperationExceptions and have the spec for Collections.unmodifiableList, unmodifiableSet, etc., return those.

@slyubomirsky
Copy link
Contributor Author

Appears there are a number of issues with actually trying to use the unmodifiable collecitons I was hoping to specify: in HashMap, JML complains of a catastrophic internal error related to the quantifiers (which don't seem very different from those in other files) and also complains of contradictory invariants (i don't know which are in contradiction). Any advice for working around these or getting to the bottom of it?

@davidcok
Copy link
Member

Steven,

  1. Guard all declarations and uses of isImmutable with //-RAC@ (and any other model or ghost fields)
  2. I would expect isImmutable to be a model field, not ghost.
  3. Usual style is to list either ghost or model as the first modifier in declarations.

@slyubomirsky
Copy link
Contributor Author

Done as suggested. I don't think I've missed any more places where there should be a -RAC but I'll give it another check soon

@RustanLeino
Copy link
Contributor

The previous Map.jml file (and quite possibly also other collection types) had an invariant

public invariant content.owner == this;

This restricts a Map from being used by more than one client. For immutable maps, one would like to allow sharing. For this reason, the invariant ought to be updated to:

public invariant isImmutable || content.owner == this;

Rustan

@leavens
Copy link
Contributor

leavens commented Sep 6, 2018 via email

@RustanLeino
Copy link
Contributor

I'm sorry, I spoke too hastily when I mentioned the isImmutable disjunct of the Map class invariant above. That invariant says that the content is owned by the Map, not that the Map belongs to someone. I was confused by a bug in OpenJML, where my suggestion here happened to step around the bug. For more details, see OpenJML/OpenJML#651.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants