eclipse-emfcloud / emfcloud-modelserver

Modelserver component
Other
40 stars 21 forks source link

API V2: IndexOutOfBoundsException when closing Transaction #212

Closed CamilleLetavernier closed 2 years ago

CamilleLetavernier commented 2 years ago

In some cases, I get this exception when closing a transaction after executing multiple commands:

org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=5, size=5
    at org.eclipse.emf.common.util.BasicEList.remove(BasicEList.java:601) ~[org.eclipse.emf.common_2.23.0.v20210924-1718.jar:?]
    at org.eclipse.emf.ecore.change.impl.ListChangeImpl.process(ListChangeImpl.java:546) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emf.ecore.change.impl.ListChangeImpl.apply(ListChangeImpl.java:476) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.apply(FeatureChangeImpl.java:701) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.getListValue(FeatureChangeImpl.java:479) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emf.ecore.change.impl.FeatureChangeImpl.getValue(FeatureChangeImpl.java:431) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emf.ecore.change.impl.ChangeDescriptionImpl.preApply(ChangeDescriptionImpl.java:826) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emf.ecore.change.impl.ChangeDescriptionImpl.getObjectsToDetach(ChangeDescriptionImpl.java:185) ~[org.eclipse.emf.ecore.change_2.14.0.v20190528-0725.jar:?]
    at org.eclipse.emfcloud.modelserver.edit.util.CommandUtil.compose(CommandUtil.java:168) ~[classes/:?]
    at org.eclipse.emfcloud.modelserver.edit.util.CommandUtil.compose(CommandUtil.java:142) ~[classes/:?]
    at java.util.stream.ReduceOps$2ReducingSink.accept(ReduceOps.java:123) ~[?:?]
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) ~[?:?]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[?:?]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
    at java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:662) ~[?:?]
    at org.eclipse.emfcloud.modelserver.emf.common.DefaultTransactionController$TransactionContext.close(DefaultTransactionController.java:348) ~[classes/:?]

It's not exactly clear to me when or why this happens, but I can reproduce it pretty consistently on some complex transactions (Typically 4 commands or more, where some commands depend on the result of the previous command).

I guess this is related to the fact that ChangeDescription is an EObject that "owns" its modified EObjects (Via containment references), and aggregating ChangeDescriptions may cause some of the descriptions to change containers, which typically causes these obscure EMF exceptions; or maybe because objectsToDetach is a changeable derived list, and trying to set it manually may cause unexpected situations.