Infinite loop when reverting back to last saved state

Issue #447 resolved
Matthias Schoettle created an issue

Under certain conditions it is possible that rolling back changes when not saving a model (e.g., when going back to the feature model) an infinite loop can occur.

This happens in CORECommandStack.goToLastSave(), because isSaveNeeded() always returns true.

The reason this happens is that:

  • saveIndex = -2
  • top = -1 or higher

I found in the source code of BasicCommandStack the following snippet:

// This is kind of tricky.
// If the saveIndex was in the redo part of the command list which has now been wiped out,
// then we can never reach a point where a save is not necessary, not even if we undo all the way back to the beginning.
//
if (saveIndex >= top)
{
  // This forces isSaveNeded to always be true.
  //
  saveIndex = -2;
}

I.e., if the user undoes some commands and then makes changes, the saveIndex will be set to -2, because the saved state can never be reached. This means that we need to be able to handle this special case somehow.

Comments (6)

  1. Matthias Schoettle reporter

    I wonder if in this case we can just unload the model and either leave it at that or reload it. I know there is a reason we don't unload all the time, only when leaving the concern (see #389).

  2. Matthias Schoettle reporter

    I briefly tried unloading (using COREModelUtil.unloadEObject() or just calling unload on the resource with demand loading the resource (using ResourceSet.getResource(URI, true). However, the aspect's eResource() returns null.

    Maybe we simply need to inform the user that it is not possible and he needs to save something.

    Anyway, it happens rarely with the following steps:

    • Make change(s)
    • Save
    • Undo
    • Make change(s)
  3. Matthias Schoettle reporter

    References #447: Adds check before reverting back to make sure it is possible.

    Adds error popup that is displayed to the user to force manual resolving. Also converts anonymous inner class to nested due to length.

    → <<cset 68004ef0117a>>

  4. Log in to comment