Amit Shrigondekar created SLING-11883:
-----------------------------------------

             Summary: JcrModifiableValueMap's cached copy of namespace prefixes 
is never refreshed
                 Key: SLING-11883
                 URL: https://issues.apache.org/jira/browse/SLING-11883
             Project: Sling
          Issue Type: Bug
            Reporter: Amit Shrigondekar


Ran into this bug in patching metadata on a resource. Patched property has 
unregistered namespace. Since user session does not have enough permissions to 
create namespace, we used a service session to register a new namespace with 
the service session, refreshed the user session, and then created a new 
resource resolver from that user session. 

When we patch the metadata properties we use something similar to this


{code:java}
ModifiableValueMap valueMap = resource.get().adaptTo(ModifiableValueMap.class); 
valueMap.put(propertyName, value);{code}
After the patch `resolver.commit()` is called. It does not recognize the 
registered namespace which causes encoded colon in the property name. 

Reason: 
JcrModifiableValueMap (an implementation of ModifiableValueMap) uses 
[escapeKeyName function in 
HelperData|https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/4ab953bf5debe2c60e1c531dc5f8f6aeb2d7414e/src/main/java/org/apache/sling/jcr/resource/internal/HelperData.java#L50]
 class which has a cached copy of namespace prefixes that never sees the latest 
changes. 



[https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/a1f5532981a118470c74afdba217fa480c1e0cec/src/main/java/org/apache/sling/jcr/resource/internal/JcrModifiableValueMap.java#L65]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to