From 34a9c0001f9596a325dfc5d35e14e4aa49af56a8 Mon Sep 17 00:00:00 2001 From: Joerg Hoh Date: Sun, 3 Aug 2025 12:22:02 +0200 Subject: [PATCH] JCRVLT-814 remove redundant calculations --- .../jackrabbit/vault/fs/impl/io/DocViewImporter.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java index 9e63fc29..ad742dd4 100644 --- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java +++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewImporter.java @@ -447,6 +447,7 @@ public void endDocViewNode(@NotNull String nodePath, @NotNull DocViewNode2 docVi } } else { NodeIterator iter = node.getNodes(); + EffectiveNodeType entParent = null; // initialize once when required while (iter.hasNext()) { numChildren++; Node child = iter.nextNode(); @@ -467,15 +468,18 @@ && isIncluded(child, child.getDepth() - rootDepth)) { } else { if (wspFilter.getImportMode(path) == ImportMode.REPLACE) { boolean shouldRemoveChild = true; + NodeDefinition childDefinition = child.getDefinition(); // check if child is not protected - if (child.getDefinition().isProtected()) { + if (childDefinition.isProtected()) { log.warn("Refuse to delete protected child node: {}", path); shouldRemoveChild = false; // check if child is mandatory (and not residual, https://s.apache.org/jcr-2.0-spec/2.0/3_Repository_Model.html#3.7.2.4%20Mandatory) - } else if (child.getDefinition().isMandatory() && !child.getDefinition().getName().equals("*")) { + } else if (childDefinition.isMandatory() && !childDefinition.getName().equals("*")) { // get relevant child node definition from parent's effective node type - EffectiveNodeType ent = EffectiveNodeType.ofNode(child.getParent()); - Optional childNodeDefinition = ent.getApplicableChildNodeDefinition(child.getName(), child.getPrimaryNodeType()); + if (entParent == null) { + entParent = EffectiveNodeType.ofNode(node); + } + Optional childNodeDefinition = entParent.getApplicableChildNodeDefinition(child.getName(), child.getPrimaryNodeType()); if (!childNodeDefinition.isPresent()) { // this should never happen as then child.getDefinition().isMandatory() would have returned false in the first place... throw new IllegalStateException("Could not find applicable child node definition for mandatory child node " + child.getPath());