You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2025/08/07 15:20:57 UTC

(jackrabbit-oak) 01/01: OAK-11845-chatty

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

reschke pushed a commit to branch OAK-11845-chatty
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git

commit 7534ce22fd055d67fc2f442534768df99e488a0e
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Thu Aug 7 16:20:33 2025 +0100

    OAK-11845-chatty
---
 .../jackrabbit/oak/core/SecureNodeBuilder.java     | 23 +++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java b/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
index 1490b11460..1f5cee1f59 100644
--- a/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
+++ b/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
@@ -156,7 +156,12 @@ class SecureNodeBuilder implements NodeBuilder {
         return builder.isReplaced(name) && !isNew(name);
     }
 
-    public synchronized void baseChanged() {
+    public void baseChanged() {
+        if (threadOfGetTreePermission != null && Thread.currentThread() != threadOfGetTreePermission) {
+            throw new RuntimeException("baseChanged() called from thread " +
+                    Thread.currentThread() + " while getTreePermission is executed by " +
+                    threadOfGetTreePermission);
+        }
         Validate.checkState(parent == null);
         treePermission = null; // trigger re-evaluation
         rootPermission = null;
@@ -343,13 +348,25 @@ class SecureNodeBuilder implements NodeBuilder {
         return builder.createBlob(stream);
     }
 
+    private volatile Thread threadOfGetTreePermission = null;
+
+    @NotNull
+    private TreePermission getTreePermission() {
+        threadOfGetTreePermission = Thread.currentThread();
+        try {
+            return internalGetTreePermission();
+        } finally {
+            threadOfGetTreePermission = null;
+        }
+    }
+
     /**
      * Permissions of this tree.
      *
      * @return The permissions for this tree.
      */
     @NotNull
-    private synchronized TreePermission getTreePermission() {
+    private TreePermission internalGetTreePermission() {
         if (treePermission == null
                 || rootPermission != rootBuilder.treePermission) {
             NodeState base = builder.getBaseState();
@@ -360,7 +377,7 @@ class SecureNodeBuilder implements NodeBuilder {
                 treePermission = requireNonNull(provider.getTreePermission(baseTree, TreePermission.EMPTY), msg);
                 rootPermission = treePermission;
             } else {
-                TreePermission parentTreePermission = Objects.requireNonNull(parent.getTreePermission(), msg);
+                TreePermission parentTreePermission = Objects.requireNonNull(parent.internalGetTreePermission(), msg);
                 treePermission = Objects.requireNonNull(parentTreePermission.getChildPermission(name, base), msg);
                 rootPermission = parent.rootPermission;
             }