This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new d422aabd3d OAK-12275: NameValidator -> improve logging for unmapped
prefixes (#2974)
d422aabd3d is described below
commit d422aabd3dc8da02d11b6f9017e59e2ff1cb889c
Author: Julian Reschke <[email protected]>
AuthorDate: Fri Jun 26 09:38:42 2026 +0200
OAK-12275: NameValidator -> improve logging for unmapped prefixes (#2974)
---
.../apache/jackrabbit/oak/plugins/name/NameValidator.java | 6 ++++--
.../jackrabbit/oak/plugins/name/NameValidatorTest.java | 15 +++++++++++----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
index 2bf981a6e8..b1792ae97f 100644
---
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
+++
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.commons.collections.ListUtils;
import org.apache.jackrabbit.oak.commons.collections.SetUtils;
import org.apache.jackrabbit.oak.spi.commit.DefaultValidator;
import org.apache.jackrabbit.oak.spi.commit.Validator;
@@ -116,8 +117,9 @@ class NameValidator extends DefaultValidator {
private void checkPrefix(String prefix) throws CommitFailedException {
if (prefix.isEmpty() || !contains(prefixes, namespaces, prefix)) {
- String msg = "Invalid namespace prefix(" + prefixes + "): " +
prefix +
- " in " + namespaces + " " +
SetUtils.toSet(namespaces.getChildNodeNames());
+ String msg = "Prefix '" + prefix + "' not present in namespace
registry. (registered) Prefixes: " + prefixes + ". " +
+ "Prefix -> Namespace mappings: " + namespaces + ", " +
+ "(escaped) Namespace -> Prefix mappings: " +
ListUtils.toList(namespaces.getChildNodeNames());
if (initPhase && !strictInitialNSChecks) {
LOG.warn(msg);
return;
diff --git
a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorTest.java
b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorTest.java
index 608ad3cd33..73f3df65bc 100644
---
a/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorTest.java
+++
b/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorTest.java
@@ -20,6 +20,7 @@ import static
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE
import static
org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants.REP_NSDATA;
import static
org.apache.jackrabbit.oak.spi.namespace.NamespaceConstants.REP_PREFIXES;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.Collections;
@@ -55,10 +56,16 @@ public class NameValidatorTest {
validator.childNodeAdded("invalid:name", EMPTY_NODE);
}
- @Test(expected = CommitFailedException.class)
- public void testInvalidPrefix() throws CommitFailedException {
- Validator validator = new NameValidator(newNamespaceNode("valid"),
false);
- validator.childNodeAdded("invalid:name", EMPTY_NODE);
+ @Test
+ public void testInvalidPrefix() {
+ try {
+ Validator validator = new NameValidator(newNamespaceNode("valid"),
false);
+ validator.childNodeAdded("invalid:name", EMPTY_NODE);
+ } catch (CommitFailedException ex) {
+ String shouldContain = "Prefix 'invalid' not present in namespace
registry";
+ assertTrue("Exception should contain >>>" + shouldContain + "<<<,
got: >>>" + ex.getMessage() + "<<<",
+ ex.getMessage().contains(shouldContain));
+ }
}
@Test(expected = CommitFailedException.class)