You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Amit Shrigondekar (Jira)" <ji...@apache.org> on 2023/05/16 20:25:00 UTC

[jira] [Updated] (SLING-11883) JcrModifiableValueMap's cached copy of namespace prefixes is never refreshed

     [ https://issues.apache.org/jira/browse/SLING-11883?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Amit Shrigondekar updated SLING-11883:
--------------------------------------
    Description: 
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, after that refreshed the user session, and then created a new resource resolver from that user session. now 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}
`resolver.commit()` is called after patching. Commit does not recognize the registered namespace which causes an 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]

  was:
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]


> 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
>            Priority: Major
>
> 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, after that refreshed the user session, and then created a new resource resolver from that user session. now 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}
> `resolver.commit()` is called after patching. Commit does not recognize the registered namespace which causes an 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)