Skip to content

Commit cc1284a

Browse files
committed
fix(model-sync-lib): fixed potential index out of bounds
Could occur when moving across parents
1 parent e057b5f commit cc1284a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

model-sync-lib/src/main/kotlin/org/modelix/model/sync/ModelImporter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ class ModelImporter(private val root: INode, val stats: ImportStats? = null) {
218218

219219
toBeMovedHere.forEach {nodeToBeMoved ->
220220
val spec = originalIdToSpec[nodeToBeMoved.originalId()]!!
221-
222-
val baseTargetIndex = spec.getIndexWithinRole(nodeData, existingChildren.lastIndex)
221+
val childrenInRole = existingChildren.filter { it.roleInParent == spec.role }
222+
val baseTargetIndex = spec.getIndexWithinRole(nodeData, childrenInRole.lastIndex)
223223
val offset = existingChildren.slice(0 until baseTargetIndex).count {
224224
!originalIdToSpec.containsKey(it.originalId()) // node will be deleted
225225
}

0 commit comments

Comments
 (0)