Skip to content

Commit c69dcbe

Browse files
committed
fix(bulk-model-sync): exception in IdentityPreservingNodeAssociation: Cannot associate ... with ...
There was an inconsistency between the implementations of `associate` and `matches` in `IdentityPreservingNodeAssociation`. Now they use the same logic.
1 parent a68b076 commit c69dcbe

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/IdentityPreservingNodeAssociation.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,26 @@ class IdentityPreservingNodeAssociation(
2424
sourceNode: IReadableNode,
2525
targetNode: IWritableNode,
2626
) {
27+
tryAssociate(sourceNode, targetNode)?.let { throw IllegalArgumentException(it) }
28+
}
29+
30+
override fun matches(
31+
sourceNode: IReadableNode,
32+
targetNode: IWritableNode,
33+
): Boolean {
34+
return tryAssociate(sourceNode, targetNode) == null
35+
}
36+
37+
private fun tryAssociate(
38+
sourceNode: IReadableNode,
39+
targetNode: IWritableNode,
40+
): String? {
2741
val sourceReference = sourceNode.getNodeReference()
2842
val expectedTargetReference = overrides[sourceReference] ?: sourceReference
2943
val actualTargetReference = targetNode.getNodeReference()
30-
require(expectedTargetReference == actualTargetReference) {
44+
return if (expectedTargetReference == actualTargetReference) {
45+
null
46+
} else {
3147
"Cannot associate $sourceReference with $actualTargetReference, expected: $expectedTargetReference"
3248
}
3349
}

0 commit comments

Comments
 (0)