Program: 75793
Project: 75793
Buggy source:
/** 
 * Create a new port with the specified name in this entity, the controller, and all the refinements.  Link these ports so that if the new port is set to be an input, output, or multiport, then the change is mirrored in the other ports.  The new port will be an instance of ModalPort, which extends TypedIOPort. This method is write-synchronized on the workspace, and increments its version number.
 * @param name The name to assign to the newly created port.
 * @return The new port.
 * @exception NameDuplicationException If the entity already has a portwith the specified name.
 */
public Port newPort(String name) throws NameDuplicationException {
  try {
    _workspace.getWriteAccess();
    Port port=new ModalPort(this,name);
    Iterator entities=entityList().iterator();
    while (entities.hasNext()) {
      Entity entity=(Entity)entities.next();
      if (entity instanceof ModalController) {
        if (entity.getPort(name) == null) {
          try {
            ((ModalController)entity)._mirrorDisable=true;
            entity.newPort(name);
          }
  finally {
            ((ModalController)entity)._mirrorDisable=false;
          }
        }
      }
 else       if (entity instanceof Refinement) {
        if (entity.getPort(name) == null) {
          try {
            ((Refinement)entity)._mirrorDisable=true;
            entity.newPort(name);
          }
  finally {
            ((Refinement)entity)._mirrorDisable=false;
          }
        }
      }
    }
    return port;
  }
 catch (  IllegalActionException ex) {
    throw new InternalErrorException("String_Node_Str" + ex.getMessage());
  }
 finally {
    _workspace.doneWriting();
  }
}

Fixed version (ground truth):
/** 
 * Create a new port with the specified name in this entity, the controller, and all the refinements.  Link these ports so that if the new port is set to be an input, output, or multiport, then the change is mirrored in the other ports.  The new port will be an instance of ModalPort, which extends TypedIOPort. This method is write-synchronized on the workspace, and increments its version number.
 * @param name The name to assign to the newly created port.
 * @return The new port.
 * @exception NameDuplicationException If the entity already has a portwith the specified name.
 */
public Port newPort(String name) throws NameDuplicationException {
  try {
    _workspace.getWriteAccess();
    ModalPort port=new ModalPort(this,name);
    Iterator entities=entityList().iterator();
    while (entities.hasNext()) {
      Entity entity=(Entity)entities.next();
      if (entity instanceof ModalController) {
        if (entity.getPort(name) == null) {
          try {
            ((ModalController)entity)._mirrorDisable=true;
            Port newPort=entity.newPort(name);
            if (newPort instanceof TypedIOPort) {
              ((TypedIOPort)newPort).setTypeSameAs(port);
            }
          }
  finally {
            ((ModalController)entity)._mirrorDisable=false;
          }
        }
      }
 else       if (entity instanceof Refinement) {
        if (entity.getPort(name) == null) {
          try {
            ((Refinement)entity)._mirrorDisable=true;
            Port newPort=entity.newPort(name);
            if (newPort instanceof TypedIOPort) {
              ((TypedIOPort)newPort).setTypeSameAs(port);
            }
          }
  finally {
            ((Refinement)entity)._mirrorDisable=false;
          }
        }
      }
    }
    return port;
  }
 catch (  IllegalActionException ex) {
    throw new InternalErrorException("String_Node_Str" + ex.getMessage());
  }
 finally {
    _workspace.doneWriting();
  }
}