This is an automated email from the ASF dual-hosted git repository. reschke pushed a commit to branch 1.22 in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/1.22 by this push: new 7da78754ce OAK-10544: oak-jcr: remapping a namespace prefix leaves namespace resolver in broken state (#1283) 7da78754ce is described below commit 7da78754ce3c2bc67f6cbfd24cc5de557f8bd375 Author: Julian Reschke <resc...@apache.org> AuthorDate: Wed Jan 24 11:31:43 2024 +0100 OAK-10544: oak-jcr: remapping a namespace prefix leaves namespace resolver in broken state (#1283) * OAK-10544: oak-jcr: remapping a namespace prefix leaves namespace resolver in broken state * Update oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java Co-authored-by: Thomas Mueller <thom...@apache.org> --------- Co-authored-by: Thomas Mueller <thom...@apache.org> --- .../org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java | 9 +++++++++ .../test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java index c6e330984e..92362aa9f2 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionNamespaces.java @@ -72,6 +72,8 @@ public class SessionNamespaces extends LocalNameMapper { "Prefix is not a valid XML NCName: " + prefix); } + String previouslyMappedUri = getOakURIOrNull(prefix); + // remove the possible existing mapping for the given prefix local.remove(prefix); @@ -86,6 +88,13 @@ public class SessionNamespaces extends LocalNameMapper { // add the new mapping local.put(prefix, uri); + + // make sure the previously mapped URI has a prefix + // (getNamespacePrefix has the side effect of generating + // a new prefix if none was found, and adding that to the local mapping) + if (previouslyMappedUri != null) { + getNamespacePrefix(previouslyMappedUri); + } } /** diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java index 1469141865..759cf0981e 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/NamePathTest.java @@ -216,7 +216,6 @@ public class NamePathTest { } @Test - @Ignore("OAK-10544") public void testPrefixRemapping() throws NamespaceException, RepositoryException { Random r = new Random(); int i1 = r.nextInt();