Patrique Legault created OAK-12462:
--------------------------------------
Summary: NodeTypeDefDiff misreports node types that declare
several residual (*) definitions
Key: OAK-12462
URL: https://issues.apache.org/jira/browse/OAK-12462
Project: Jackrabbit Oak
Issue Type: Bug
Components: core
Affects Versions: 2.4.0, 1.88.0
Reporter: Patrique Legault
{{NodeTypeDefDiff}} gives wrong results for node types that declare more than
one residual ({{*}}) property definition or more than one child node definition
with the same name. Such types are common in practice, e.g.
{noformat}
[cust:workItem] > nt:base
- nodeId (string)
- * (undefined)
- * (undefined) multiple
- workflowId (string)
+ metaData (nt:unstructured)
{noformat}
Observed with oak-core 1.88.0; the relevant code is unchanged on 2.4.0.
h3. 1. A pure reorder of residual property definitions is reported as MAJOR
Old definition: {{- * (undefined)}} then {{- * (undefined) multiple}}. New
definition: the same two rules in the opposite order. Nothing changed, but
{{NodeTypeDefDiff.create(old, new)}} returns {{MAJOR}} with
{noformat}
PropDefDiff[itemName=*, type=MAJOR, operation=MODIFIED]
{noformat}
Cause: {{buildPropDefDiffs()}} keys definitions by {{PropertyDefinitionId}} =
(declaring type, name, definesResidual) in a {{HashMap}}. All {{*}} definitions
of a type get the same key, so only the last one of each side survives and the
two survivors are compared (here multiple vs. single valued). For the same
reason an added or removed residual property definition can go unreported. This
is the problem described in OAK-3307 (port of JCR-3902), which is still open.
h3. 2. Several child node definitions with the same name: only one pair is
reported
Old definition with three residual child rules, e.g. {{+ * (nt:folder)}}, {{+ *
(nt:file)}}, {{+ * (nt:unstructured)}}:
* the same three rules reordered: {{TRIVIAL}}, one {{ChildNodeDefDiff}}
reported (expected: {{NONE}});
* {{sameNameSiblings}} changed from true to false on one of them: one
{{TRIVIAL}} {{ChildNodeDefDiff}} (expected: {{MAJOR}});
* one of the three rules removed: one {{TRIVIAL}} {{ChildNodeDefDiff}}, no
removal reported (expected: a {{REMOVED}} diff, {{MAJOR}}).
Cause: {{ChildNodeDefDiffs.getChildNodeDefDiffs()}} builds all old x new pairs,
sorts them by compatibility, and uses {{alreadyMatched()}} to skip pairs whose
definitions are already used, comparing with {{NodeDefinition.equals()}}. Since
OAK-9591, {{ItemDefinitionImpl.equals()}} compares only the declaring node type
({{Objects.equals(type, other.type)}}), so all definitions declared by the same
type are equal to each other. After the first pair is selected, every other
pair is considered already matched, so only one pair is ever reported.
The same {{equals()}} is used by {{ChildItemDefDiff.isModified()}}. The
declaring types are compared through {{NodeTypeImpl.equals()}} (CND string), so
the {{MODIFIED}} / {{NONE}} operation of an item diff reflects whether the
whole type changed, not whether that item changed.
h3. Impact
{{TypeEditorProvider}} uses this diff to decide whether a node type change
needs a repository scan, so a pure reorder of residual definitions triggers an
unnecessary full scan. Tooling that compares two versions of a type (e.g. to
decide whether a type registered on another repository can be accepted) cannot
rely on the result for such types.
h3. Reproduction
Register the old CND in one repository and the new CND in another (or the same
type name in two {{MemoryNodeStore}} instances via
{{CndImporter.registerNodeTypes}}), then:
{code:java}
NodeType oldType =
ReadOnlyNodeTypeManager.getInstance(RootFactory.createReadOnlyRoot(oldStore.getRoot()),
NamePathMapper.DEFAULT).getNodeType("cust:workItem");
NodeType newType =
ReadOnlyNodeTypeManager.getInstance(RootFactory.createReadOnlyRoot(newStore.getRoot()),
NamePathMapper.DEFAULT).getNodeType("cust:workItem");
NodeTypeDefDiff diff = NodeTypeDefDiff.create(oldType, newType);
// pure reorder of the two '*' property rules: diff.getType() == MAJOR,
expected NONE
{code}
h3. Suggested direction
Match definitions on their full signature instead of (declaring type, name):
for property definitions name + required type + multiple; for child node
definitions name + set of required primary types. Compare the remaining
attributes (mandatory, protected, autoCreated, defaults, constraints,
sameNameSiblings, ...) between matched definitions. Unit tests for the cases
above would also address the concern raised in OAK-3307.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)