Skip to content
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

Overriding methods restricting parameters #232

Open
wmdietl opened this issue May 3, 2022 · 0 comments
Open

Overriding methods restricting parameters #232

wmdietl opened this issue May 3, 2022 · 0 comments

Comments

@wmdietl
Copy link
Member

wmdietl commented May 3, 2022

Collection defines retainAll as taking a Collection<?> c parameter, meaning a collection with possibly null elements:
https://github.com/eisop/jdk/blob/a4b7e04c9a6fa0c9451b3064464a46b943fa40a6/src/java.base/share/classes/java/util/Collection.java#L597

Certain subclasses, e.g. LinkedBlockingDeque override that method to take a Collection<? extends @NonNull Object> c parameter, forbidding null values
https://github.com/eisop/jdk/blob/a4b7e04c9a6fa0c9451b3064464a46b943fa40a6/src/java.base/share/classes/java/util/concurrent/LinkedBlockingDeque.java#L1353

This matches the description of the logic of the method but is an unsound covariant change.

eisop/jdk#9 changes the signature to match the overridden method.
Is there a sound way to specify the relation between these methods, without resorting to arbitrary pre-conditions? (In JML one could add a predicate to Collection that decides whether it accepts null. retainAll would have a pre-condition that the predicate of this and c matches (maybe this being "weaker" than c).)

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

No branches or pull requests

1 participant