Program: 74222
Project: 74222
Buggy source:
/** 
 * Move the refinements in the configurer of this state to the closest modal model above this state in the model hierarchy.
 */
private void _populateRefinements() throws IllegalActionException {
  CompositeEntity container=(CompositeEntity)getContainer();
  CompositeEntity modalModel=(CompositeEntity)container.getContainer();
  if (!(modalModel instanceof TypedCompositeActor)) {
    if (modalModel == null) {
      try {
        modalModel=new ModalModel(workspace());
        container.setContainer(modalModel);
      }
 catch (      NameDuplicationException e) {
      }
    }
 else {
      return;
    }
  }
  List<ComponentEntity> entities=new LinkedList<ComponentEntity>(_configurer.entityList());
  if (container instanceof RefinementActor) {
    RefinementActor actor=(RefinementActor)container;
    for (    ComponentEntity entity : entities) {
      String name=modalModel.uniqueName(entity.getName());
      actor.addRefinement(this,name,null,entity.getClassName(),null);
      String moml=new DesignPatternGetMoMLAction().getMoml(entity,name);
      UpdateContentsRequest request=new UpdateContentsRequest(this,modalModel,name,moml);
      modalModel.requestChange(request);
      try {
        entity.setContainer(null);
      }
 catch (      NameDuplicationException e) {
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Move the refinements in the configurer of this state to the closest modal model above this state in the model hierarchy.
 */
private void _populateRefinements() throws IllegalActionException {
  CompositeEntity container=(CompositeEntity)getContainer();
  CompositeEntity modalModel=(CompositeEntity)container.getContainer();
  boolean isModalModelInvisible=modalModel != null && !modalModel.attributeList(InvisibleModalModel.class).isEmpty();
  if (!(modalModel instanceof TypedCompositeActor) || isModalModelInvisible) {
    if (modalModel == null || isModalModelInvisible) {
      try {
        if (modalModel == null) {
          modalModel=new ModalModel(workspace());
          new InvisibleModalModel(modalModel,modalModel.uniqueName("String_Node_Str"));
          container.setContainer(modalModel);
        }
      }
 catch (      NameDuplicationException e) {
      }
      saveRefinementsInConfigurer.setToken(BooleanToken.TRUE);
    }
 else {
      return;
    }
  }
  List<ComponentEntity> entities=new LinkedList<ComponentEntity>(_configurer.entityList());
  if (container instanceof RefinementActor) {
    RefinementActor actor=(RefinementActor)container;
    for (    ComponentEntity entity : entities) {
      String oldName=entity.getName();
      String newName=modalModel.uniqueName(oldName);
      String refinements=refinementName.getExpression();
      String[] names=refinements.split("String_Node_Str");
      boolean changed=false;
      StringBuffer newRefinements=new StringBuffer();
      for (      String part : names) {
        if (newRefinements.length() > 0) {
          newRefinements.append("String_Node_Str");
        }
        if (part.equals(oldName)) {
          changed=true;
        }
 else {
          newRefinements.append(part);
        }
      }
      if (changed) {
        refinementName.setExpression(newRefinements.toString());
      }
      actor.addRefinement(this,newName,null,entity.getClassName(),null);
      String moml=new DesignPatternGetMoMLAction().getMoml(entity,newName);
      try {
        entity.setContainer(null);
      }
 catch (      NameDuplicationException e) {
      }
      UpdateContentsRequest request=new UpdateContentsRequest(this,modalModel,newName,moml);
      modalModel.requestChange(request);
    }
  }
}