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

"nt:unstructured" is used in case of overwriting node with no sling:resourceType property defined (JCR Resource Merger)

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Resource Merger 1.4.0
    • Resource Merger 1.4.2
    • ResourceResolver
    • None

    Description

      https://github.com/apache/sling-org-apache-sling-resourcemerger/blob/c9d742c8080a0976b778c678747d99289c9efbb7/src/main/java/org/apache/sling/resourcemerger/impl/MergedResource.java#L75

      In this constructor, I see the following logic:
      1. Try to find the sling:resourceType property, set in any of the resources
      2. If that property could not be found, try using the relative path

      Then, even if a proper sling:resourceType property was found, it will overwrite that value with the result of Resource#getResourceType if it is not null, of the last resource that defines one. This could be entirely right (maybe this done because some people use wrappers, that override the getResourceType-method?).

      However, in the JCR implementation of Resource (JcrNodeResource/JcrItemResource), it is rare for getResourceType to return null, because:
      1. Try to return the defined sling:resourceType's value
      2. If not found, try to return the value of jcr:primaryType

      Generally, any node has a jcr:primaryType defined and thus returns it.

      When the overridden resource does not mention a resource type, this effectively makes getResourceType of the merged resource return the node type of the overridden resource (in our case: nt:unstructured).

      Easy case to reproduce:

      /libs/test (@jcr:primaryType: nt:unstructured, @sling:resourceType=website/component, @prop=test)
      /apps/test (@jcr:primaryType: nt:unstructured, @prop=test-overridden)

      ->

      resource.getResourceType(): nt:unstructured
      resource.getResourceSuperType(): website/component
      resource.getValueMap().get("prop"): test-overridden
      resource.getValueMap().get("sling:resourceType"): website/component

      (Marked in the bold, the values I think are not correct in this case.)

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            Henry Kuijpers Henry Kuijpers

            Dates

              Created:
              Updated:

              Issue deployment