You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Carsten Ziegeler (Jira)" <ji...@apache.org> on 2021/10/27 05:07:00 UTC

[jira] [Commented] (SLING-8269) Generics in ResourceProvider SPI don't resolve

    [ https://issues.apache.org/jira/browse/SLING-8269?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17434663#comment-17434663 ] 

Carsten Ziegeler commented on SLING-8269:
-----------------------------------------

[~jsedding] I'm not sure how we can resolve this apart from adding a little bit to the docs?

> Generics in ResourceProvider SPI don't resolve
> ----------------------------------------------
>
>                 Key: SLING-8269
>                 URL: https://issues.apache.org/jira/browse/SLING-8269
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: API 2.11.0
>            Reporter: Julian Sedding
>            Priority: Minor
>
> In the "new" {{ResourceProvider}} SPI a resource provider always "owns" its root. This means that below that path no other RP is asked for resources (unless it's registered on a more specific root path). In order to allow for the scenario where a RP falls back to \{{Resource}}s provided by other RPs, an API was added, that I gather should be used as follows:
> {code:java}
> public Iterator<Resource> listChildren(ResolveContext<Whatever> ctx, Resource parent) {
>     Iterator<Resource> ownChildren = ... // compute child resource
>     ResolveContext<?> parentCtx = ctx.getParentResolveContext();
>     ResourceProvider<?> parentProvider = ctx.getParentResourceProvider();
>     if (parentCtx == null || parentProvider == null) {
>         return null;
>     }
>     return merge(ownChildren, parentProvider.listChildren(parentCtx, parent));
> }
> {code}
>  
>  However, the {{parentCtx}} on the last line does not match the signature of {{listChildren(ResourceContext<T>, Resource)}}, because the generic type of both {{ResolveContext<?>}} and {{ResourceContext<T>}} (from the {{listChildren}} method signature) do not match, leading to the following compile-time error:
> {noformat}
> incompatible types: org.apache.sling.spi.resource.provider.ResolveContext<capture#1 of ?> cannot be converted to org.apache.sling.spi.resource.provider.ResolveContext<capture#2 of ?>
> {noformat}
> This can be worked around by dropping generic types of the local variables and accepting an "unchecked type" warning, i.e.:
> {code:java}
> ResolveContext parentCtx = ctx.getParentResolveContext();
> ResourceProvider parentProvider = ctx.getParentResourceProvider();
> {code}
> cc [~cziegeler]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)