Program: 74431
Project: 74431
Buggy source:
/** 
 * Create a new entity from the specified class name, give it the specified entity name, and specify that its container is the current container object.  If the current container already contains an entity with the specified name and class, then return that entity.  If the class name matches a class that has been previously defined in the scope (or with an absolute name), then that class is instantiated. Otherwise, the class name is interpreted as a Java class name and we attempt to construct the entity.  If instantiating a Java class doesn't work, then we look for a MoML file on the classpath that defines a class by this name.  The file is assumed to be named "foo.xml", where "foo" is the name of the class.  Moreover, the classname is assumed to have no periods (since a MoML name does not allow periods, this is reasonable). If _current is not an instance of CompositeEntity, then an XML exception is thrown. If an object is created and we are propagating, then that object is marked as a derived object. The third argument, if non-null, gives a URL to import to create a reference class from which to instantiate this entity.
 * @param className
 * @param entityName
 * @param source
 * @return
 * @exception Exception
 */
private NamedObj _createEntity(String className,String entityName,String source) throws Exception {
  if ((_current != null) && !(_current instanceof CompositeEntity)) {
    throw new XmlException("String_Node_Str" + "String_Node_Str" + "String_Node_Str" + _current + "String_Node_Str",_currentExternalEntity(),_getLineNumber(),_getColumnNumber());
  }
  CompositeEntity container=(CompositeEntity)_current;
  ComponentEntity previous=_searchForEntity(entityName,_current);
  Class newClass=null;
  ComponentEntity reference=null;
  if (className != null) {
    reference=searchForClass(className,source);
    if ((reference == null) && (source == null)) {
      reference=_searchForClassInContext(className,null);
    }
    if (reference == null) {
      try {
        newClass=Class.forName(className,true,_classLoader);
      }
 catch (      Exception ex) {
        try {
          reference=_attemptToFindMoMLClass(className,source);
        }
 catch (        Exception ex2) {
          throw new IllegalActionException(null,ex2,"String_Node_Str" + className);
        }
      }
catch (      Error error) {
        StringBuffer errorMessage=new StringBuffer();
        if (error instanceof ExceptionInInitializerError) {
          Throwable staticThrowable=((ExceptionInInitializerError)error).getCause();
          errorMessage.append("String_Node_Str" + "String_Node_Str" + KernelException.stackTraceToString(staticThrowable));
        }
 else {
          errorMessage.append(className + "String_Node_Str" + error.toString()+ "String_Node_Str");
        }
        try {
          reference=_attemptToFindMoMLClass(className,source);
        }
 catch (        XmlException ex2) {
          throw new Exception("String_Node_Str" + errorMessage.toString() + className+ "String_Node_Str"+ ex2.getMessage());
        }
catch (        ClassFormatError ex3) {
          throw new Exception("String_Node_Str" + errorMessage.toString() + className+ "String_Node_Str"+ "String_Node_Str"+ ex3.getMessage());
        }
catch (        Exception ex4) {
          throw new Exception("String_Node_Str" + errorMessage.toString() + className+ "String_Node_Str"+ ex4.getMessage());
        }
      }
    }
  }
  if (previous != null) {
    if (newClass != null) {
      _checkClass(previous,newClass,"String_Node_Str" + entityName + "String_Node_Str"+ className);
    }
    return previous;
  }
  _checkForNull(className,"String_Node_Str");
  if (reference == null) {
    if (_current != null) {
      List derivedList=container.getDerivedList();
      Iterator derivedObjects=derivedList.iterator();
      while (derivedObjects.hasNext()) {
        CompositeEntity derived=(CompositeEntity)derivedObjects.next();
        if (derived.getEntity(entityName) != null) {
          throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + derived.getEntity(entityName).getFullName());
        }
      }
      _checkClass(_current,CompositeEntity.class,"String_Node_Str" + "String_Node_Str" + _current);
      Object[] arguments=new Object[2];
      arguments[0]=_current;
      arguments[1]=entityName;
      NamedObj newEntity=_createInstance(newClass,arguments);
      newEntity.propagateExistence();
      _loadIconForClass(className,newEntity);
      _addParamsToParamsToParse(newEntity);
      return newEntity;
    }
 else {
      Object[] arguments=new Object[1];
      arguments[0]=_workspace;
      NamedObj result=_createInstance(newClass,arguments);
      result.setName(entityName);
      _loadIconForClass(className,result);
      return result;
    }
  }
 else {
    if (!reference.isClassDefinition()) {
      throw new MissingClassException("String_Node_Str" + "String_Node_Str" + reference.getFullName(),reference.getFullName(),_currentExternalEntity(),_getLineNumber(),_getColumnNumber());
    }
    List derivedList=null;
    if (container != null) {
      derivedList=container.getDerivedList();
      Iterator derivedObjects=derivedList.iterator();
      while (derivedObjects.hasNext()) {
        CompositeEntity derived=(CompositeEntity)derivedObjects.next();
        if (derived.getEntity(entityName) != null) {
          throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + derived.getEntity(entityName).getFullName());
        }
      }
    }
    ComponentEntity newEntity=(ComponentEntity)reference.instantiate(container,entityName);
    if ((_topObjectsCreated != null) && (container == _originalContext)) {
      _topObjectsCreated.add(newEntity);
    }
    URIAttribute modelURI=(URIAttribute)newEntity.getAttribute("String_Node_Str",URIAttribute.class);
    if (modelURI != null) {
      modelURI.setContainer(null);
    }
    _markParametersToParse(newEntity);
    newEntity.setClassName(className);
    Iterator propagatedInstances=newEntity.propagateExistence().iterator();
    while (propagatedInstances.hasNext()) {
      ComponentEntity propagatedEntity=(ComponentEntity)propagatedInstances.next();
      URIAttribute propagatedURI=(URIAttribute)propagatedEntity.getAttribute("String_Node_Str",URIAttribute.class);
      if (propagatedURI != null) {
        propagatedURI.setContainer(null);
      }
    }
    return newEntity;
  }
}

Fixed version (ground truth):
/** 
 * Create a new entity from the specified class name, give it the specified entity name, and specify that its container is the current container object.  If the current container already contains an entity with the specified name and class, then return that entity.  If the class name matches a class that has been previously defined in the scope (or with an absolute name), then that class is instantiated. Otherwise, the class name is interpreted as a Java class name and we attempt to construct the entity.  If instantiating a Java class doesn't work, then we look for a MoML file on the classpath that defines a class by this name.  The file is assumed to be named "foo.xml", where "foo" is the name of the class.  Moreover, the classname is assumed to have no periods (since a MoML name does not allow periods, this is reasonable). If _current is not an instance of CompositeEntity, then an XML exception is thrown. If an object is created and we are propagating, then that object is marked as a derived object. The third argument, if non-null, gives a URL to import to create a reference class from which to instantiate this entity.
 * @param className
 * @param entityName
 * @param source
 * @return
 * @exception Exception
 */
private NamedObj _createEntity(String className,String entityName,String source) throws Exception {
  if ((_current != null) && !(_current instanceof CompositeEntity)) {
    throw new XmlException("String_Node_Str" + "String_Node_Str" + "String_Node_Str" + _current + "String_Node_Str",_currentExternalEntity(),_getLineNumber(),_getColumnNumber());
  }
  CompositeEntity container=(CompositeEntity)_current;
  ComponentEntity previous=_searchForEntity(entityName,_current);
  Class newClass=null;
  ComponentEntity reference=null;
  if (className != null) {
    reference=searchForClass(className,source);
    if ((reference == null) && (source == null)) {
      reference=_searchForClassInContext(className,null);
    }
    if (reference == null || !reference.isClassDefinition()) {
      try {
        newClass=Class.forName(className,true,_classLoader);
      }
 catch (      Exception ex) {
        try {
          reference=_attemptToFindMoMLClass(className,source);
        }
 catch (        Exception ex2) {
          throw new IllegalActionException(null,ex2,"String_Node_Str" + className);
        }
      }
catch (      Error error) {
        StringBuffer errorMessage=new StringBuffer();
        if (error instanceof ExceptionInInitializerError) {
          Throwable staticThrowable=((ExceptionInInitializerError)error).getCause();
          errorMessage.append("String_Node_Str" + "String_Node_Str" + KernelException.stackTraceToString(staticThrowable));
        }
 else {
          errorMessage.append(className + "String_Node_Str" + error.toString()+ "String_Node_Str");
        }
        try {
          reference=_attemptToFindMoMLClass(className,source);
        }
 catch (        XmlException ex2) {
          throw new Exception("String_Node_Str" + errorMessage.toString() + className+ "String_Node_Str"+ ex2.getMessage());
        }
catch (        ClassFormatError ex3) {
          throw new Exception("String_Node_Str" + errorMessage.toString() + className+ "String_Node_Str"+ "String_Node_Str"+ ex3.getMessage());
        }
catch (        Exception ex4) {
          throw new Exception("String_Node_Str" + errorMessage.toString() + className+ "String_Node_Str"+ ex4.getMessage());
        }
      }
    }
  }
  if (previous != null) {
    if (newClass != null) {
      _checkClass(previous,newClass,"String_Node_Str" + entityName + "String_Node_Str"+ className);
    }
    return previous;
  }
  _checkForNull(className,"String_Node_Str");
  if (reference == null || (!reference.isClassDefinition() && newClass != null)) {
    if (_current != null) {
      List derivedList=container.getDerivedList();
      Iterator derivedObjects=derivedList.iterator();
      while (derivedObjects.hasNext()) {
        CompositeEntity derived=(CompositeEntity)derivedObjects.next();
        if (derived.getEntity(entityName) != null) {
          throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + derived.getEntity(entityName).getFullName());
        }
      }
      _checkClass(_current,CompositeEntity.class,"String_Node_Str" + "String_Node_Str" + _current);
      Object[] arguments=new Object[2];
      arguments[0]=_current;
      arguments[1]=entityName;
      NamedObj newEntity=_createInstance(newClass,arguments);
      newEntity.propagateExistence();
      _loadIconForClass(className,newEntity);
      _addParamsToParamsToParse(newEntity);
      return newEntity;
    }
 else {
      Object[] arguments=new Object[1];
      arguments[0]=_workspace;
      NamedObj result=_createInstance(newClass,arguments);
      result.setName(entityName);
      _loadIconForClass(className,result);
      return result;
    }
  }
 else {
    if (!reference.isClassDefinition()) {
      throw new MissingClassException("String_Node_Str" + "String_Node_Str" + reference.getFullName() + "String_Node_Str"+ className+ "String_Node_Str"+ entityName+ "String_Node_Str"+ source,reference.getFullName(),_currentExternalEntity(),_getLineNumber(),_getColumnNumber());
    }
    List derivedList=null;
    if (container != null) {
      derivedList=container.getDerivedList();
      Iterator derivedObjects=derivedList.iterator();
      while (derivedObjects.hasNext()) {
        CompositeEntity derived=(CompositeEntity)derivedObjects.next();
        if (derived.getEntity(entityName) != null) {
          throw new IllegalActionException(container,"String_Node_Str" + "String_Node_Str" + derived.getEntity(entityName).getFullName());
        }
      }
    }
    ComponentEntity newEntity=(ComponentEntity)reference.instantiate(container,entityName);
    if ((_topObjectsCreated != null) && (container == _originalContext)) {
      _topObjectsCreated.add(newEntity);
    }
    URIAttribute modelURI=(URIAttribute)newEntity.getAttribute("String_Node_Str",URIAttribute.class);
    if (modelURI != null) {
      modelURI.setContainer(null);
    }
    _markParametersToParse(newEntity);
    newEntity.setClassName(className);
    Iterator propagatedInstances=newEntity.propagateExistence().iterator();
    while (propagatedInstances.hasNext()) {
      ComponentEntity propagatedEntity=(ComponentEntity)propagatedInstances.next();
      URIAttribute propagatedURI=(URIAttribute)propagatedEntity.getAttribute("String_Node_Str",URIAttribute.class);
      if (propagatedURI != null) {
        propagatedURI.setContainer(null);
      }
    }
    return newEntity;
  }
}