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

Unmodifiable map wrappers to not shield from Entry.setValue() #244

Open
vigna opened this issue Mar 18, 2021 · 3 comments
Open

Unmodifiable map wrappers to not shield from Entry.setValue() #244

vigna opened this issue Mar 18, 2021 · 3 comments

Comments

@vigna
Copy link
Owner

vigna commented Mar 18, 2021

The current way entrySet() is handled in unmodifiable wrapper is wrong—users can still modify the map using Entry.setValue(). An entirely custom unmodifiable wrapper is necessary (as the JDK does).

@techsy730
Copy link
Contributor

Why doesn't giving the raw entry/keySet to unmodifiableSet and then returning that work?
Same for values and unmodifiableCollection.

@vigna
Copy link
Owner Author

vigna commented Apr 24, 2021

Because making an entry set unmodifiable simply means that you cannot add or remove entries. It does not prevent you from reading an entry and invoking setValue(), thus modifying the underlying collection. Key sets and value collections do not have this problem.

@techsy730
Copy link
Contributor

techsy730 commented Apr 28, 2021

Ah, I see.
I think It can be done without defining a new composition class from scratch. Just make a (package private) variantion of unmodifiableSet that will also wrap the Entry values. (Best approach would probably be a subclass of UnmodifiableSet, and override any ways of getting values to instead return the wrapper Entrys)

Would require some care, but we won't have to implement a whole wrapper from scratch.

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

2 participants