adapt ConfigOptionProvider javadoc to reality #3761
Conversation
@@ -28,8 +28,7 @@ | |||
* the parameter name for which the requested options shall be returned | |||
* @param locale | |||
* locale | |||
* @return the configuration options provided by this provider (not | |||
* null, could be empty) | |||
* @return the configuration options provided by this provider if any (may be null) |
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.
So, can you add some information on which situations we should return an empty collection and on which one we should return null?
What makes the difference?
Can we also change the current implementations in the ESH repo to use a consistent logic.
E.g.
- the URI is not handled => null, otherwise empty or filled collection
- URI or param not handled => null, otherwise a collection that contains the parameter
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.
What is the value of differentiating it?
I simply adapted to JavaDoc do explicitly allow returning null, i.e. to indicate that the caller is able to handle it.
Isn't it much simpler to be able to use: for (final ParameterOption option : provider.getParameterOptions()) {
...
} instead of final Collection<ParameterOption> options = provider.getParameterOptions();
if (options != null) {
for (final ParameterOption option : provider.getParameterOptions()) {
...
}
}
If there is no difference between an empty collection and null, I would prefer to change the implementation. Shouldn't be the documentation of the API be as detailed as possible? |
No, it is changed to fit the implementation of the caller. We have a similar pattern everywhere (e.g. ThingHandlerFactories, ConfigDescriptionProviders, StateDescriptionProvider,....): They all are allowed to return null in case they don't have anything to contribute. |
I made the javadoc more clear so that it does not imply anymore that there is a difference between an empty collection and null. Also, I changed the persistence service registry to return null in case it does not have anything. It was the only implementation that alway returned an empty collection. |
Thanks. What about |
...as several implementations return null. Also, it does not make much sense to instantiate empty collections all the time, as the majority of call will be returned with no results. Signed-off-by: Simon Kaufmann <simon.kfm@googlemail.com>
Ouch, well... Had it closed because I was switching between old branches and therefore missed it. Thanks for catching this! |
Travis failed because of the Magic bundle test. |
See: #3781 |
Related to: #3761 (comment) Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
...as several implementations return null. Also, it does not make
much sense to instantiate empty collections all the time, as the
majority of call will be returned with no results.
Signed-off-by: Simon Kaufmann simon.kfm@googlemail.com