Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-8269

Generics in ResourceProvider SPI don't resolve

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • API 2.11.0
    • None
    • API
    • None

    Description

      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:

      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));
      }
      

       
      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:

      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 ?>
      

      This can be worked around by dropping generic types of the local variables and accepting an "unchecked type" warning, i.e.:

      ResolveContext parentCtx = ctx.getParentResolveContext();
      ResourceProvider parentProvider = ctx.getParentResourceProvider();
      

      cc cziegeler

      Attachments

        Activity

          People

            Unassigned Unassigned
            jsedding Julian Sedding
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: