You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2021/11/02 06:28:45 UTC

[sling-org-apache-sling-jcr-resource] branch master updated: SLING-10899 : Result of JcrNodeResource#adaptTo(ValueMap.class) should be cached

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-resource.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c09c1e  SLING-10899 : Result of JcrNodeResource#adaptTo(ValueMap.class) should be cached
7c09c1e is described below

commit 7c09c1e99cba3e5545af05028e88aa518f3272d9
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Nov 2 07:28:36 2021 +0100

    SLING-10899 : Result of JcrNodeResource#adaptTo(ValueMap.class) should be cached
---
 .../sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
index 70596ad..c38ad9a 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
@@ -70,6 +70,8 @@ class JcrNodeResource extends JcrItemResource<Node> { // this should be package
 
     private final HelperData helper;
 
+    private volatile ValueMap valueMap;
+
     /**
      * Constructor
      * @param resourceResolver
@@ -133,7 +135,10 @@ class JcrNodeResource extends JcrItemResource<Node> { // this should be package
         } else if (type == InputStream.class) {
             return (Type) getInputStream(); // unchecked cast
         } else if (type == Map.class || type == ValueMap.class) {
-            return (Type) new JcrValueMap(getNode(), this.helper); // unchecked cast
+            if ( valueMap == null ) {
+                valueMap = new JcrValueMap(getNode(), this.helper);
+            }
+            return (Type) valueMap; // unchecked cast
         } else if (type == ModifiableValueMap.class ) {
             // check write
             try {