-
Notifications
You must be signed in to change notification settings - Fork 36
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
Wiring javadoc claims that instances are effectively immutable #175
Comments
The lists returned from the wiring types must be mutable copies. That is, they are a snapshot (copy) and since they are a copy, there is no reason that they should not be mutable. This allows the caller to do things like sort the returned list, combine lists, etc., without having to make another copy. |
On the other hand, if a caller obtains the list without the need to mutate it (for example just iterates over it), returning a mutable copy just adds a performance penalty. |
Generally, in OSGi api when we state a returned value is a snapshot, we mean that it is a copy and thus wont change underneath the user. Had the api said an immutable value, then it would allow us to return an immutable value. But snapshot allows for the caller to mutate the value. In a framework implementation, it can use a list implementation which wraps an immutable list and converts to a mutable list upon first mutation request (copy-on-write). Then, for many users which don't mutate, there is little additional memory overhead. |
In this case it should be mutable.
That's a good solution to meet the APIs convention and maintain a good performance and memory-usage. |
See Wiring javadoc. It claims:
This is incorrect for at least the method
org.osgi.resource.Wiring.getProvidedResourceWires(String)
which will change over time as new resources get wired to capabilities provided by the wiring. ForBundleWiring
which extendsWiring
this is also untrue for the methodorg.osgi.resource.Wiring.getRequiredResourceWires(String)
for bundle revisions that have dynamic imports and get wired to new packages dynamically.the get methods on Wiring all use the language:
It is unclear why the returned lists use the term "snapshot" if the instance is immutable. Why would a snapshot be used for something that never changes? Assuming the results can change, is it acceptable for an implementation to return immutable "snapshot" lists? Or does this language imply the return list is mutable?
The text was updated successfully, but these errors were encountered: