Program: 75216
Project: 75216
Buggy source:
/** 
 * Generate Giotto code for the given model.
 * @return The Giotto code.
 */
public void compileTypedCompositeActor(TypedCompositeActor compositeActor) throws IllegalActionException {
  try {
    List opaqueCompositeActors=_containedOpaqueCompositeActors(compositeActor);
    Iterator opaqueCompositeActorsIterator=opaqueCompositeActors.iterator();
    while (opaqueCompositeActorsIterator.hasNext()) {
      TypedCompositeActor containedCompositeActor=(TypedCompositeActor)opaqueCompositeActorsIterator.next();
      compileTypedCompositeActor(containedCompositeActor);
    }
    CompositeEntity container=(CompositeEntity)compositeActor.getContainer();
    if (container == null) {
      return;
    }
    FunctionDependencyOfCompositeActor functionDependency=((FunctionDependencyOfCompositeActor)compositeActor.getFunctionDependency());
    DirectedGraph detailedDependencyGraph=functionDependency.getDetailedDependencyGraph();
    List listOfSubgraphs=detailedDependencyGraph.subgraphs();
    Object[] arrayOfSubgraphs=listOfSubgraphs.toArray();
    Collection[] inputPortsInSubgraphs=new Collection[listOfSubgraphs.size()];
    if (listOfSubgraphs.size() == 1) {
      return;
    }
    Iterator inputPorts=compositeActor.inputPortList().iterator();
    while (inputPorts.hasNext()) {
      IOPort inputPort=(IOPort)inputPorts.next();
      for (int i=0; i < arrayOfSubgraphs.length; i++) {
        DirectedGraph subgraph=(DirectedGraph)arrayOfSubgraphs[i];
        if (subgraph.containsNodeWeight(inputPort)) {
          if (inputPortsInSubgraphs[i] == null) {
            inputPortsInSubgraphs[i]=new LinkedList();
          }
          inputPortsInSubgraphs[i].add(inputPort);
          break;
        }
      }
    }
    for (int i=0; i < inputPortsInSubgraphs.length; i++) {
      Collection inputs=inputPortsInSubgraphs[i];
      if (inputs == null) {
        continue;
      }
      TypedCompositeActor clone=(TypedCompositeActor)compositeActor.clone();
      clone.setName("String_Node_Str" + compositeActor.getName() + "String_Node_Str"+ i);
      clone.setContainer(container);
      Collection inputNodes=detailedDependencyGraph.nodes(inputs);
      DirectedGraph subgraph=new DirectedGraph();
      detailedDependencyGraph.connectedSubGraph(inputNodes,subgraph);
      List entitiesOfClone=clone.deepEntityList();
      List entitiesOfOrigin=compositeActor.deepEntityList();
      for (int j=entitiesOfClone.size() - 1; j >= 0; j--) {
        ComponentEntity cloneEntity=(ComponentEntity)entitiesOfClone.get(j);
        ComponentEntity originalEntity=(ComponentEntity)entitiesOfOrigin.get(j);
        Iterator portsOfOriginalEntity=originalEntity.portList().listIterator();
        boolean originalEntityInSubgraph=false;
        while (portsOfOriginalEntity.hasNext() && !originalEntityInSubgraph) {
          IOPort portOfOriginalEntity=(IOPort)portsOfOriginalEntity.next();
          if (subgraph.containsNodeWeight(portOfOriginalEntity)) {
            originalEntityInSubgraph=true;
          }
        }
        if (!originalEntityInSubgraph) {
          Iterator relations=cloneEntity.linkedRelationList().listIterator();
          while (relations.hasNext()) {
            IORelation relation=(IORelation)relations.next();
            relation.setContainer(null);
          }
          cloneEntity.setContainer(null);
        }
      }
      List portsOfClone=clone.portList();
      List portsOfOrigin=compositeActor.portList();
      for (int j=portsOfClone.size() - 1; j >= 0; j--) {
        IOPort portOfClone=(IOPort)portsOfClone.get(j);
        IOPort portOfOrigin=(IOPort)portsOfOrigin.get(j);
        if (!subgraph.containsNodeWeight(portOfOrigin)) {
          portOfClone.setContainer(null);
        }
 else {
          Iterator relations=portOfOrigin.linkedRelationList().iterator();
          while (relations.hasNext()) {
            IORelation relation=(IORelation)relations.next();
            portOfClone.link(relation);
          }
        }
      }
    }
    compositeActor.setContainer(null);
  }
 catch (  KernelException ex) {
    System.out.println(ex.getMessage());
    throw new IllegalActionException(ex.getMessage());
  }
catch (  CloneNotSupportedException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * Generate Giotto code for the given model.
 * @return The Giotto code.
 */
public void compileTypedCompositeActor(TypedCompositeActor compositeActor) throws IllegalActionException {
  try {
    List opaqueCompositeActors=_containedOpaqueCompositeActors(compositeActor);
    Iterator opaqueCompositeActorsIterator=opaqueCompositeActors.iterator();
    while (opaqueCompositeActorsIterator.hasNext()) {
      TypedCompositeActor containedCompositeActor=(TypedCompositeActor)opaqueCompositeActorsIterator.next();
      compileTypedCompositeActor(containedCompositeActor);
    }
    CompositeEntity container=(CompositeEntity)compositeActor.getContainer();
    if (container == null) {
      return;
    }
    FunctionDependencyOfCompositeActor functionDependency=((FunctionDependencyOfCompositeActor)compositeActor.getFunctionDependency());
    DirectedGraph detailedDependencyGraph=functionDependency.getDetailedDependencyGraph();
    List listOfSubgraphs=detailedDependencyGraph.subgraphs();
    Object[] arrayOfSubgraphs=listOfSubgraphs.toArray();
    Collection[] inputPortsInSubgraphs=new Collection[listOfSubgraphs.size()];
    if (listOfSubgraphs.size() == 1) {
      return;
    }
    Iterator inputPorts=compositeActor.inputPortList().iterator();
    while (inputPorts.hasNext()) {
      IOPort inputPort=(IOPort)inputPorts.next();
      for (int i=0; i < arrayOfSubgraphs.length; i++) {
        DirectedGraph subgraph=(DirectedGraph)arrayOfSubgraphs[i];
        if (subgraph.containsNodeWeight(inputPort)) {
          if (inputPortsInSubgraphs[i] == null) {
            inputPortsInSubgraphs[i]=new LinkedList();
          }
          inputPortsInSubgraphs[i].add(inputPort);
          break;
        }
      }
    }
    for (int i=0; i < inputPortsInSubgraphs.length; i++) {
      Collection inputs=inputPortsInSubgraphs[i];
      if (inputs == null) {
        continue;
      }
      TypedCompositeActor clone=(TypedCompositeActor)compositeActor.clone();
      clone.setName("String_Node_Str" + compositeActor.getName() + "String_Node_Str"+ i);
      clone.setContainer(container);
      Collection inputNodes=detailedDependencyGraph.nodes(inputs);
      DirectedGraph subgraph=detailedDependencyGraph.connectedSubGraph(inputNodes);
      List entitiesOfClone=clone.deepEntityList();
      List entitiesOfOrigin=compositeActor.deepEntityList();
      for (int j=entitiesOfClone.size() - 1; j >= 0; j--) {
        ComponentEntity cloneEntity=(ComponentEntity)entitiesOfClone.get(j);
        ComponentEntity originalEntity=(ComponentEntity)entitiesOfOrigin.get(j);
        Iterator portsOfOriginalEntity=originalEntity.portList().listIterator();
        boolean originalEntityInSubgraph=false;
        while (portsOfOriginalEntity.hasNext() && !originalEntityInSubgraph) {
          IOPort portOfOriginalEntity=(IOPort)portsOfOriginalEntity.next();
          if (subgraph.containsNodeWeight(portOfOriginalEntity)) {
            originalEntityInSubgraph=true;
          }
        }
        if (!originalEntityInSubgraph) {
          Iterator relations=cloneEntity.linkedRelationList().listIterator();
          while (relations.hasNext()) {
            IORelation relation=(IORelation)relations.next();
            relation.setContainer(null);
          }
          cloneEntity.setContainer(null);
        }
      }
      List portsOfClone=clone.portList();
      List portsOfOrigin=compositeActor.portList();
      for (int j=portsOfClone.size() - 1; j >= 0; j--) {
        IOPort portOfClone=(IOPort)portsOfClone.get(j);
        IOPort portOfOrigin=(IOPort)portsOfOrigin.get(j);
        if (!subgraph.containsNodeWeight(portOfOrigin)) {
          portOfClone.setContainer(null);
        }
 else {
          Iterator relations=portOfOrigin.linkedRelationList().iterator();
          while (relations.hasNext()) {
            IORelation relation=(IORelation)relations.next();
            portOfClone.link(relation);
          }
        }
      }
    }
    compositeActor.setContainer(null);
    functionDependency=(FunctionDependencyOfCompositeActor)((CompositeActor)container).getFunctionDependency();
    functionDependency.getDetailedDependencyGraph();
  }
 catch (  KernelException ex) {
    System.out.println(ex.getMessage());
    throw new IllegalActionException(ex.getMessage());
  }
catch (  CloneNotSupportedException e) {
    e.printStackTrace();
  }
}