[
https://issues.apache.org/jira/browse/SLING-5664?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15245325#comment-15245325
]
Konrad Windszus commented on SLING-5664:
----------------------------------------
The reason for `SlingScriptHelper` to be used in the past (whenever possible,
i.e. when the adaptable is a request and the SlingScriptHelper is available at
all) is that it will release the reference towards the OSGi service sooner (as
soon as the request is closed). When using the `BundleContext` there is a
mechanism regarding phantom references (therefore those services will be
released later, depending on the garbage collection).
So basically we have two options:
# rely on the fix from SLING-5665 (which makes this fix incomplete/not working,
unless you have the most recent version of Sling Scripting Core, 2.0.38)
# remove usage of `SlingScriptHelper` as done in the attached script and live
with the fact, that service references live a bit longer
I would be in favor of 2.).
> Models: OSGiServiceInjector does not consider service.ranking
> -------------------------------------------------------------
>
> Key: SLING-5664
> URL: https://issues.apache.org/jira/browse/SLING-5664
> Project: Sling
> Issue Type: Bug
> Components: Extensions
> Affects Versions: Sling Models Impl 1.2.6
> Reporter: Konrad Windszus
> Assignee: Konrad Windszus
> Fix For: Sling Models Impl 1.2.8
>
> Attachments: SLING-5664-v01.patch
>
>
> The injector is using {{BundleContext.getServiceReferences(Class, String)}}
> or {{SlingScriptHelper.getServices(Class, String)}}
> (https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/injectors/OSGiServiceInjector.java#L97).
> From the returned array it just takes the first item.
> Unfortunately the order in that array is not-deterministic, especially it is
> not necessarily that way that items with a higher service.ranking are
> returned first.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)