Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@solcott Thanks for the PR!
Could you explain more why this is needed? Did you still encounter the same issue #772 even after PR #972 was merged?
If so it would be useful to see some code that's generating the error, ideally in the form of unit tests.
My understanding of
Collections.unmodifiableX()is that it's just a wrapper around the underlying data structure so it should still respect the ordering enforced by the implementation, in our case theLinkedHashSet.Collection.iteratorandSet.iteratorboth have effectively the same language in the Javadocs:cc @jeffdgr8 as the contributor of PR #972
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the source for
UnmodifiableSet, it subclassesUnmodifiableCollection, additionally overridingequals()andhashCode()to delegate to the wrapped collection.I would not expect this change to affect the iteration order, which should have been resolved in my PR. But I would expect this change to allow for comparisons between multiple versions of the wrapped collection itself. For example:
@solcott do you have a similar usage that requires comparisons of these
MapObject.Collections for equality?I think this is a good change either way, as it would allow for these kinds of comparisons.
Collectionitself doesn't stipulate a contract forequals()beyondObject.equals, butSetdoes, which is the underlying collection we're using here.If this is the contract we want to support and there are use cases for it, it may make sense to change the signature of
getObjects()and related functions that call it to explicitly return aSetrather than the more generalCollectiontype. That way it would enforce this behavior expectation at the API level. This would be a non-breaking safe API change, sinceSetis aCollection.