Program: 75670
Project: 75670
Buggy source:
private void _relationsAndLinks() throws IllegalActionException {
  try {
    if (_subAgents.size() == 0) {
      if (_transitions.size() == 0) {
        Integrator integrator=new Integrator(_container,"String_Node_Str");
        Expression expression=new Expression(_container,"String_Node_Str");
        expression.expression.setExpression(_expression);
        TypedIOPort expressionOutput=expression.output;
        TypedIOPort integratorInput=integrator.input;
        if (getInputs().size() == 0) {
          TypeAttribute ta=new TypeAttribute(expressionOutput,"String_Node_Str");
          ta.setExpression("String_Node_Str");
        }
        Parameter signalType;
        TypedIORelation relation0=new TypedIORelation(_container,"String_Node_Str");
        expressionOutput.link(relation0);
        integratorInput.link(relation0);
        integrator.initialState.setExpression(_initialState);
        ListIterator exprInputs=_expressionInputs.listIterator();
        while (exprInputs.hasNext()) {
          String inputPortName=(String)exprInputs.next();
          TypedIOPort expressionInput=new TypedIOPort(expression,inputPortName,true,false);
          if (_container instanceof Refinement) {
            signalType=new Parameter(expressionInput,"String_Node_Str",new StringToken("String_Node_Str"));
          }
        }
        if (_assertion != "String_Node_Str") {
          Assertion assertion=new Assertion(_container,"String_Node_Str");
          assertion.assertion.setExpression(_assertion);
          ListIterator asserInputs=_assertionInputs.listIterator();
          while (asserInputs.hasNext()) {
            String inputPortName=(String)asserInputs.next();
            TypedIOPort expressionInput=new TypedIOPort(assertion,inputPortName,true,false);
            if (_container instanceof Refinement) {
              signalType=new Parameter(expressionInput,"String_Node_Str",new StringToken("String_Node_Str"));
            }
          }
        }
        ListIterator outputs=getOutputs().listIterator();
        if (getOutputs().size() > 1)         throw new IllegalActionException("String_Node_Str");
        while (outputs.hasNext()) {
          String outputStr=(String)outputs.next();
          TypedIOPort containerOutput=new TypedIOPort(_container,outputStr,false,true);
          TypedIORelation relation1=new TypedIORelation(_container,"String_Node_Str");
          TypedIOPort integratorOutput=integrator.output;
          integratorOutput.link(relation1);
          containerOutput.link(relation1);
        }
        ListIterator inputs=getInputs().listIterator();
        while (inputs.hasNext()) {
          String inputStr=(String)inputs.next();
          TypedIOPort _containerInput=new TypedIOPort(_container,inputStr,true,false);
          TypedIOPort expressionInput=new TypedIOPort(expression,inputStr,true,false);
          if (_container instanceof Refinement) {
            signalType=new Parameter(expressionInput,"String_Node_Str",new StringToken("String_Node_Str"));
          }
        }
      }
 else {
        FSMActor controller=((FSMDirector)_container.getDirector()).getController();
        ListIterator transitions=_transitions.listIterator();
        int transitionIndex=0;
        while (transitions.hasNext()) {
          TxtTransition transition=(TxtTransition)transitions.next();
          System.out.println("String_Node_Str" + transition.getState() + "String_Node_Str"+ transition.getNextState());
          try {
            State initState=controller.getInitialState();
          }
 catch (          IllegalActionException e) {
            controller.initialStateName.setExpression(transition.getState());
          }
          State state=_getState(controller,transition.getState());
          State nextState=_getState(controller,transition.getNextState());
          if (state.getRefinement() == null) {
            Refinement refinement=new Refinement(_container,transition.getState());
          }
          if (nextState.getRefinement() == null) {
            Refinement refinement=new Refinement(_container,transition.getNextState());
          }
          state.refinementName.setExpression(transition.getState());
          nextState.refinementName.setExpression(transition.getNextState());
          Agent modeState=(Agent)_searchAgent(transition.getState() + "String_Node_Str",CharonProcessor.modesList);
          Agent referMode=(Agent)_searchAgent(transition.getState() + "String_Node_Str",_subModes);
          Refinement stateRefinement=(Refinement)state.getRefinement()[0];
          if (modeState != null && referMode != null) {
            ListIterator parameters=modeState.getParameters().listIterator();
            ListIterator referParas=referMode.getParameters().listIterator();
            while (parameters.hasNext()) {
              String parameter=(String)parameters.next();
              String referPara=(String)referParas.next();
              Parameter para=new Parameter(state,parameter);
              Parameter refinementPara=new Parameter(stateRefinement,parameter);
              para.setExpression(referPara);
              refinementPara.setExpression(referPara);
            }
            modeState.setName(transition.getState());
            modeState.addMode(modeState.getContent());
            modeState.constructor(stateRefinement);
          }
          Transition fsmTransition=new Transition(controller,transition.getState() + "String_Node_Str" + transition.getNextState());
          fsmTransition.guardExpression.setExpression(transition.getCondition());
          fsmTransition.reset.setExpression("String_Node_Str");
          fsmTransition.setActions.setExpression(transition.getNextState() + "String_Node_Str" + getOutputs().get(0));
          state.outgoingPort.link(fsmTransition);
          nextState.incomingPort.link(fsmTransition);
        }
        ListIterator outputs=getOutputs().listIterator();
        while (outputs.hasNext()) {
          String outputStr=(String)outputs.next();
          ModalPort _containerOutput=(ModalPort)_container.newPort(outputStr);
          _containerOutput.setOutput(true);
        }
        ListIterator inputs=getInputs().listIterator();
        while (inputs.hasNext()) {
          String inputStr=(String)inputs.next();
          ModalPort _containerInput=(ModalPort)_container.newPort(inputStr);
          _containerInput.setInput(true);
        }
      }
    }
 else {
      ListIterator outputs=getOutputs().listIterator();
      if (getOutputs().size() > 1)       throw new IllegalActionException("String_Node_Str");
      while (outputs.hasNext()) {
        String outputStr=(String)outputs.next();
        TypedIOPort _containerOutput=new TypedIOPort(_container,outputStr,false,true);
      }
      ListIterator inputs=getInputs().listIterator();
      while (inputs.hasNext()) {
        String inputStr=(String)inputs.next();
        TypedIOPort _containerInput=new TypedIOPort(_container,inputStr,true,false);
      }
      ListIterator agents=_subAgents.listIterator();
      while (agents.hasNext()) {
        Agent subAgent=(Agent)agents.next();
        Agent agent=(Agent)_searchAgent(subAgent.getName(),CharonProcessor.agentsList);
        agent.constructor(_container);
      }
    }
    System.out.println("String_Node_Str");
    int relationIndex=2;
    ListIterator entities=_container.entityList().listIterator();
    while (entities.hasNext()) {
      Actor actor=(Actor)entities.next();
      System.out.println("String_Node_Str" + ((Nameable)actor).getFullName());
      ListIterator inputs=actor.inputPortList().listIterator();
      while (inputs.hasNext()) {
        TypedIOPort input=(TypedIOPort)inputs.next();
        System.out.println("String_Node_Str" + input.getFullName());
        if (input.linkedRelationList().size() > 0)         continue;
        TypedIOPort source=_searchSource(input);
        TypedIORelation relation;
        if (source != null) {
          List relations;
          if (((NamedObj)source.getContainer()).depthInHierarchy() == ((NamedObj)input.getContainer()).depthInHierarchy()) {
            relations=source.linkedRelationList();
          }
 else {
            relations=source.insideRelationList();
          }
          System.out.println("String_Node_Str" + source.getFullName() + "String_Node_Str"+ relations.size());
          if (relations.size() > 1) {
            throw new IllegalActionException("String_Node_Str");
          }
 else           if (relations.size() == 1) {
            relation=(TypedIORelation)relations.get(0);
          }
 else {
            relation=new TypedIORelation(_container,"String_Node_Str" + relationIndex);
            relationIndex++;
            source.link(relation);
          }
          input.link(relation);
        }
      }
    }
    if (_container instanceof ModalModel) {
      ListIterator containerOutputs=_container.outputPortList().listIterator();
      while (containerOutputs.hasNext()) {
        TypedIOPort containerOutput=(TypedIOPort)containerOutputs.next();
        TypedIORelation containerOutputRelation=(TypedIORelation)containerOutput.insideRelationList().get(0);
        entities=_container.entityList().listIterator();
        while (entities.hasNext()) {
          Actor actor=(Actor)entities.next();
          if (!(actor instanceof ModalController)) {
            System.out.println("String_Node_Str" + ((Nameable)actor).getFullName());
            ListIterator outputs=actor.outputPortList().listIterator();
            while (outputs.hasNext()) {
              TypedIOPort output=(TypedIOPort)outputs.next();
              System.out.println("String_Node_Str" + output.getFullName());
              if (output.linkedRelationList().size() > 0) {
                ListIterator orelations=output.linkedRelationList().listIterator();
                while (orelations.hasNext()) {
                  TypedIORelation tir=(TypedIORelation)orelations.next();
                  System.out.println(tir.linkedSourcePortList());
                }
              }
 else {
                output.link(containerOutputRelation);
              }
            }
          }
        }
      }
    }
 else {
      ListIterator sinks=_container.outputPortList().listIterator();
      while (sinks.hasNext()) {
        TypedIOPort sink=(TypedIOPort)sinks.next();
        System.out.println("String_Node_Str" + sink.getFullName());
        TypedIOPort source=_searchSource(sink);
        TypedIORelation relation;
        if (source != null) {
          List relations=source.linkedRelationList();
          System.out.println("String_Node_Str" + source.getFullName() + "String_Node_Str"+ relations.size());
          if (relations.size() > 1) {
            throw new IllegalActionException("String_Node_Str");
          }
 else           if (relations.size() == 1) {
            relation=(TypedIORelation)relations.get(0);
            sink.link(relation);
          }
 else {
            List myRelations=sink.insideRelationList();
            System.out.println(sink.getName() + "String_Node_Str" + myRelations.size());
            if (myRelations.size() > 1) {
              throw new IllegalActionException("String_Node_Str");
            }
 else             if (myRelations.size() == 1) {
              relation=(TypedIORelation)myRelations.get(0);
            }
 else {
              relation=new TypedIORelation(_container,"String_Node_Str" + relationIndex);
              relationIndex++;
              sink.link(relation);
            }
            source.link(relation);
          }
          relations=sink.insideRelationList();
          System.out.println("String_Node_Str" + sink.getName() + "String_Node_Str"+ relations.size());
          System.out.println("String_Node_Str" + relation.linkedPortList().size());
        }
      }
    }
  }
 catch (  NameDuplicationException e) {
    throw new IllegalActionException(e.getMessage());
  }
}

Fixed version (ground truth):
private void _relationsAndLinks() throws IllegalActionException {
  try {
    if (_subAgents.size() == 0) {
      if (_transitions.size() == 0) {
        Integrator integrator=new Integrator(_container,"String_Node_Str");
        Expression expression=new Expression(_container,"String_Node_Str");
        expression.expression.setExpression(_expression);
        TypedIOPort expressionOutput=expression.output;
        TypedIOPort integratorInput=integrator.input;
        if (getInputs().size() == 0) {
          TypeAttribute ta=new TypeAttribute(expressionOutput,"String_Node_Str");
          ta.setExpression("String_Node_Str");
        }
        Parameter signalType;
        TypedIORelation relation0=new TypedIORelation(_container,"String_Node_Str");
        expressionOutput.link(relation0);
        integratorInput.link(relation0);
        integrator.initialState.setExpression(_initialState);
        ListIterator exprInputs=_expressionInputs.listIterator();
        while (exprInputs.hasNext()) {
          String inputPortName=(String)exprInputs.next();
          TypedIOPort expressionInput=new TypedIOPort(expression,inputPortName,true,false);
          if (_container instanceof Refinement) {
            signalType=new Parameter(expressionInput,"String_Node_Str",new StringToken("String_Node_Str"));
          }
        }
        if (_assertion != "String_Node_Str") {
          Assertion assertion=new Assertion(_container,"String_Node_Str");
          assertion.assertion.setExpression(_assertion);
          ListIterator asserInputs=_assertionInputs.listIterator();
          while (asserInputs.hasNext()) {
            String inputPortName=(String)asserInputs.next();
            TypedIOPort expressionInput=new TypedIOPort(assertion,inputPortName,true,false);
            if (_container instanceof Refinement) {
              signalType=new Parameter(expressionInput,"String_Node_Str",new StringToken("String_Node_Str"));
            }
          }
        }
        ListIterator outputs=getOutputs().listIterator();
        if (getOutputs().size() > 1)         throw new IllegalActionException("String_Node_Str");
        while (outputs.hasNext()) {
          String outputStr=(String)outputs.next();
          TypedIOPort containerOutput=new TypedIOPort(_container,outputStr,false,true);
          TypedIORelation relation1=new TypedIORelation(_container,"String_Node_Str");
          TypedIOPort integratorOutput=integrator.output;
          integratorOutput.link(relation1);
          containerOutput.link(relation1);
        }
        ListIterator inputs=getInputs().listIterator();
        while (inputs.hasNext()) {
          String inputStr=(String)inputs.next();
          TypedIOPort _containerInput=new TypedIOPort(_container,inputStr,true,false);
          TypedIOPort expressionInput=new TypedIOPort(expression,inputStr,true,false);
          if (_container instanceof Refinement) {
            signalType=new Parameter(expressionInput,"String_Node_Str",new StringToken("String_Node_Str"));
          }
        }
      }
 else {
        FSMActor controller=((FSMDirector)_container.getDirector()).getController();
        ListIterator transitions=_transitions.listIterator();
        int transitionIndex=0;
        while (transitions.hasNext()) {
          TxtTransition transition=(TxtTransition)transitions.next();
          System.out.println("String_Node_Str" + transition.getState() + "String_Node_Str"+ transition.getNextState());
          try {
            State initState=controller.getInitialState();
          }
 catch (          IllegalActionException e) {
            controller.initialStateName.setExpression(transition.getState());
          }
          State state=_getState(controller,transition.getState());
          State nextState=_getState(controller,transition.getNextState());
          Agent modeState=(Agent)_searchAgent(transition.getState() + "String_Node_Str",CharonProcessor.modesList);
          Agent referMode=(Agent)_searchAgent(transition.getState() + "String_Node_Str",_subModes);
          if (modeState != null && referMode != null) {
            if (state.getRefinement() == null) {
              Refinement refinement=new Refinement(_container,transition.getState());
            }
            if (nextState.getRefinement() == null) {
              Refinement refinement=new Refinement(_container,transition.getNextState());
            }
            state.refinementName.setExpression(transition.getState());
            nextState.refinementName.setExpression(transition.getNextState());
            Refinement stateRefinement=(Refinement)state.getRefinement()[0];
            ListIterator parameters=modeState.getParameters().listIterator();
            ListIterator referParas=referMode.getParameters().listIterator();
            while (parameters.hasNext()) {
              String parameter=(String)parameters.next();
              String referPara=(String)referParas.next();
              Parameter para=new Parameter(state,parameter);
              Parameter refinementPara=new Parameter(stateRefinement,parameter);
              para.setExpression(referPara);
              refinementPara.setExpression(referPara);
            }
            modeState.setName(transition.getState());
            modeState.addMode(modeState.getContent());
            modeState.constructor(stateRefinement);
          }
          Transition fsmTransition=new Transition(controller,transition.getState() + "String_Node_Str" + transition.getNextState());
          fsmTransition.guardExpression.setExpression(transition.getCondition());
          fsmTransition.reset.setExpression("String_Node_Str");
          if (modeState != null) {
            System.out.println("String_Node_Str" + transition.getState());
            fsmTransition.setActions.setExpression(transition.getNextState() + "String_Node_Str" + getOutputs().get(0));
          }
          state.outgoingPort.link(fsmTransition);
          nextState.incomingPort.link(fsmTransition);
        }
        ListIterator outputs=getOutputs().listIterator();
        while (outputs.hasNext()) {
          String outputStr=(String)outputs.next();
          ModalPort _containerOutput=(ModalPort)_container.newPort(outputStr);
          _containerOutput.setOutput(true);
        }
        ListIterator inputs=getInputs().listIterator();
        while (inputs.hasNext()) {
          String inputStr=(String)inputs.next();
          ModalPort _containerInput=(ModalPort)_container.newPort(inputStr);
          _containerInput.setInput(true);
        }
      }
    }
 else {
      ListIterator outputs=getOutputs().listIterator();
      if (getOutputs().size() > 1)       throw new IllegalActionException("String_Node_Str");
      while (outputs.hasNext()) {
        String outputStr=(String)outputs.next();
        TypedIOPort _containerOutput=new TypedIOPort(_container,outputStr,false,true);
      }
      ListIterator inputs=getInputs().listIterator();
      while (inputs.hasNext()) {
        String inputStr=(String)inputs.next();
        TypedIOPort _containerInput=new TypedIOPort(_container,inputStr,true,false);
      }
      ListIterator agents=_subAgents.listIterator();
      while (agents.hasNext()) {
        Agent subAgent=(Agent)agents.next();
        Agent agent=(Agent)_searchAgent(subAgent.getName(),CharonProcessor.agentsList);
        agent.constructor(_container);
      }
    }
    System.out.println("String_Node_Str");
    int relationIndex=2;
    ListIterator entities=_container.entityList().listIterator();
    while (entities.hasNext()) {
      Actor actor=(Actor)entities.next();
      System.out.println("String_Node_Str" + ((Nameable)actor).getFullName());
      ListIterator inputs=actor.inputPortList().listIterator();
      while (inputs.hasNext()) {
        TypedIOPort input=(TypedIOPort)inputs.next();
        System.out.println("String_Node_Str" + input.getFullName());
        if (input.linkedRelationList().size() > 0)         continue;
        TypedIOPort source=_searchSource(input);
        TypedIORelation relation;
        if (source != null) {
          List relations;
          if (((NamedObj)source.getContainer()).depthInHierarchy() == ((NamedObj)input.getContainer()).depthInHierarchy()) {
            relations=source.linkedRelationList();
          }
 else {
            relations=source.insideRelationList();
          }
          System.out.println("String_Node_Str" + source.getFullName() + "String_Node_Str"+ relations.size());
          if (relations.size() > 1) {
            throw new IllegalActionException("String_Node_Str");
          }
 else           if (relations.size() == 1) {
            relation=(TypedIORelation)relations.get(0);
          }
 else {
            relation=new TypedIORelation(_container,"String_Node_Str" + relationIndex);
            relationIndex++;
            source.link(relation);
          }
          input.link(relation);
        }
      }
    }
    if (_container instanceof ModalModel) {
      ListIterator containerOutputs=_container.outputPortList().listIterator();
      while (containerOutputs.hasNext()) {
        TypedIOPort containerOutput=(TypedIOPort)containerOutputs.next();
        TypedIORelation containerOutputRelation=(TypedIORelation)containerOutput.insideRelationList().get(0);
        entities=_container.entityList().listIterator();
        while (entities.hasNext()) {
          Actor actor=(Actor)entities.next();
          if (!(actor instanceof ModalController)) {
            System.out.println("String_Node_Str" + ((Nameable)actor).getFullName());
            ListIterator outputs=actor.outputPortList().listIterator();
            while (outputs.hasNext()) {
              TypedIOPort output=(TypedIOPort)outputs.next();
              System.out.println("String_Node_Str" + output.getFullName());
              if (output.linkedRelationList().size() > 0) {
                ListIterator orelations=output.linkedRelationList().listIterator();
                while (orelations.hasNext()) {
                  TypedIORelation tir=(TypedIORelation)orelations.next();
                  System.out.println(tir.linkedSourcePortList());
                }
              }
 else {
                output.link(containerOutputRelation);
              }
            }
          }
        }
      }
    }
 else {
      ListIterator sinks=_container.outputPortList().listIterator();
      while (sinks.hasNext()) {
        TypedIOPort sink=(TypedIOPort)sinks.next();
        System.out.println("String_Node_Str" + sink.getFullName());
        TypedIOPort source=_searchSource(sink);
        TypedIORelation relation;
        if (source != null) {
          List relations=source.linkedRelationList();
          System.out.println("String_Node_Str" + source.getFullName() + "String_Node_Str"+ relations.size());
          if (relations.size() > 1) {
            throw new IllegalActionException("String_Node_Str");
          }
 else           if (relations.size() == 1) {
            relation=(TypedIORelation)relations.get(0);
            sink.link(relation);
          }
 else {
            List myRelations=sink.insideRelationList();
            System.out.println(sink.getName() + "String_Node_Str" + myRelations.size());
            if (myRelations.size() > 1) {
              throw new IllegalActionException("String_Node_Str");
            }
 else             if (myRelations.size() == 1) {
              relation=(TypedIORelation)myRelations.get(0);
            }
 else {
              relation=new TypedIORelation(_container,"String_Node_Str" + relationIndex);
              relationIndex++;
              sink.link(relation);
            }
            source.link(relation);
          }
          relations=sink.insideRelationList();
          System.out.println("String_Node_Str" + sink.getName() + "String_Node_Str"+ relations.size());
          System.out.println("String_Node_Str" + relation.linkedPortList().size());
        }
      }
    }
  }
 catch (  NameDuplicationException e) {
    throw new IllegalActionException(e.getMessage());
  }
}