[
https://issues.apache.org/jira/browse/SLING-11030?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17463282#comment-17463282
]
Karl Pauls commented on SLING-11030:
------------------------------------
Additionally, I think it would be good to improve the getService call to keep
looping over the references until one did actually return a service. Like it is
right now, it might return null even so there would have been a different
service available. Obviously, the callback should then be seeded with the ref
that was used (i.e., the first that didn't return null) - if any.
Futhermore, the getService_s_ has a similar issue where it a) might end up
returning an empty array (if there was no ref returning a service) - instead,
it should return null if the array is empty in the end and regardless, it
should filter out the refs that returned null from the refs given to the
callback.
> OSGiServiceInjector.getService() calls ungetService even if service is not get
> ------------------------------------------------------------------------------
>
> Key: SLING-11030
> URL: https://issues.apache.org/jira/browse/SLING-11030
> Project: Sling
> Issue Type: Bug
> Components: Sling Models
> Affects Versions: Models Implementation 1.5.0
> Reporter: Carsten Ziegeler
> Priority: Major
> Fix For: Models Implementation 1.5.2
>
>
> The getService method gets all service references, but only from one of them
> it gets the service. However all service references are passed in to the
> callback for disposal. So for all references an unget is called, although it
> happened only for one
> In addition, the code is assuming that the service with the highest ranking
> is always gettable. A null check is missing at :
> https://github.com/apache/sling-org-apache-sling-models-impl/blob/89fcb8702e29ad3322ee2a023ae6b24e5d2f83ab/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java#L114
>
> It would be better to loop over the services references until one returns non
> null and then only dispose that reference later
--
This message was sent by Atlassian Jira
(v8.20.1#820001)