Program: 73360
Project: 73360
Buggy source:
/** 
 * Check for problems in the moml to be copied.  If there are missing variables references, search for the variables and return MoML definitions for any found variables.
 * @param momlToBeChecked The MoML string to be checked.
 * @param container The container in which the string is to be checked.
 * @param hideVariables If true, add MoML that will make all the foundvariables hidden from the user interface when they are copied.
 * @return MoML to be inserted before the momlToBeChecked
 * @exception IllegalActionException If there is a problem parsingthe string, or validating a variable.
 */
public String checkCopy(String momlToBeChecked,NamedObj container,boolean hideVariables) throws IllegalActionException {
  _variableBuffer=new StringWriter();
  Workspace workspace=new Workspace("String_Node_Str");
  MoMLParser parser=new MoMLParser(workspace);
  TypedCompositeActor parsedContainer=null;
  boolean doParse=true;
  while (doParse) {
    ErrorHandler handler=MoMLParser.getErrorHandler();
    MoMLParser.setErrorHandler(null);
    try {
      parsedContainer=(TypedCompositeActor)parser.parse("String_Node_Str" + _variableBuffer.toString() + momlToBeChecked+ "String_Node_Str");
      doParse=false;
    }
 catch (    MissingClassException ex1) {
      try {
        doParse=_findMissingClass(ex1,container,parsedContainer);
      }
 catch (      Exception ex1a) {
        return _variableBuffer.toString();
      }
    }
catch (    IllegalActionException ex2) {
      try {
        doParse=_findUndefinedConstantsOrIdentifiers(ex2,container,parsedContainer,hideVariables);
      }
 catch (      Exception ex2a) {
        return _variableBuffer.toString();
      }
    }
catch (    Exception ex3) {
      throw new IllegalActionException(container,ex3,"String_Node_Str");
    }
 finally {
      MoMLParser.setErrorHandler(handler);
    }
  }
  if (parsedContainer != null) {
    Iterator entities=parsedContainer.deepEntityList().iterator();
    while (entities.hasNext()) {
      Entity entity=(Entity)entities.next();
      List<Attribute> entityAttributes=new LinkedList<Attribute>(entity.attributeList());
      for (      Attribute attribute : entityAttributes) {
        _recursiveFindUndefinedConstantsOrIdentifiesInAttribute(attribute,container,parsedContainer,hideVariables);
      }
    }
    List<Attribute> allAttributes=new LinkedList<Attribute>(parsedContainer.attributeList());
    for (    Attribute attribute : allAttributes) {
      _recursiveFindUndefinedConstantsOrIdentifiesInAttribute(attribute,container,parsedContainer,hideVariables);
    }
  }
  return _variableBuffer.toString();
}

Fixed version (ground truth):
/** 
 * Check for problems in the moml to be copied.  If there are missing variables references, search for the variables and return MoML definitions for any found variables.
 * @param momlToBeChecked The MoML string to be checked.
 * @param container The container in which the string is to be checked.
 * @param hideVariables If true, add MoML that will make all the foundvariables hidden from the user interface when they are copied.
 * @return MoML to be inserted before the momlToBeChecked
 * @exception IllegalActionException If there is a problem parsingthe string, or validating a variable.
 */
public String checkCopy(String momlToBeChecked,NamedObj container,boolean hideVariables) throws IllegalActionException {
  _variableBuffer=new StringWriter();
  Workspace workspace=new Workspace("String_Node_Str");
  MoMLParser parser=new MoMLParser(workspace);
  TypedCompositeActor parsedContainer=null;
  boolean doParse=true;
  while (doParse) {
    ErrorHandler handler=MoMLParser.getErrorHandler();
    MoMLParser.setErrorHandler(null);
    try {
      parsedContainer=(TypedCompositeActor)parser.parse("String_Node_Str" + _variableBuffer.toString() + momlToBeChecked+ "String_Node_Str");
      doParse=false;
    }
 catch (    MissingClassException ex1) {
      try {
        doParse=_findMissingClass(ex1,container,parsedContainer);
      }
 catch (      Exception ex1a) {
        return _variableBuffer.toString();
      }
    }
catch (    IllegalActionException ex2) {
      try {
        doParse=_findUndefinedConstantsOrIdentifiers(ex2,container,parsedContainer,hideVariables);
      }
 catch (      Throwable throwable) {
        return _variableBuffer.toString();
      }
    }
catch (    Exception ex3) {
      throw new IllegalActionException(container,ex3,"String_Node_Str");
    }
 finally {
      MoMLParser.setErrorHandler(handler);
    }
  }
  if (parsedContainer != null) {
    Iterator entities=parsedContainer.deepEntityList().iterator();
    while (entities.hasNext()) {
      Entity entity=(Entity)entities.next();
      List<Attribute> entityAttributes=new LinkedList<Attribute>(entity.attributeList());
      for (      Attribute attribute : entityAttributes) {
        _recursiveFindUndefinedConstantsOrIdentifiesInAttribute(attribute,container,parsedContainer,hideVariables);
      }
    }
    List<Attribute> allAttributes=new LinkedList<Attribute>(parsedContainer.attributeList());
    for (    Attribute attribute : allAttributes) {
      _recursiveFindUndefinedConstantsOrIdentifiesInAttribute(attribute,container,parsedContainer,hideVariables);
    }
  }
  return _variableBuffer.toString();
}