Program: 72786
Project: 72786
Buggy source:
/** 
 * Generate the .moml file for this nesC application.
 * @param componentName The name of the component (no suffix).
 * @param outputFile The file to generate.
 * @param directorOutputDir The output directory to pass to thePtinyOSDirector.
 * @param opts The compiler options (PFLAGS) to pass to thePtinyOSDirector.
 * @param micaboardFile Path to the MoML file that contains theWireless wrapper.  Null if wrapper should not be generated.
 * @exception IllegalActionException If there is a problem creatingan interface IOport or connection.
 * @exception NameDuplicationException If there is a problem creatingan interface IOport or connection.
 */
public void generatePtinyOSModel(String componentName,String outputFile,String directorOutputDir,String opts,String micaboardFile) throws IllegalActionException, NameDuplicationException {
  Element root=null;
  Element director=null;
  DocType plot=new DocType("String_Node_Str","String_Node_Str","String_Node_Str");
  Document doc=null;
  if (micaboardFile != null) {
    Element micaboard=null;
    try {
      SAXBuilder saxbuilder=new SAXBuilder();
      Document docWireless=saxbuilder.build(new File(micaboardFile));
      Filter filter=new ContentFilter(ContentFilter.ELEMENT);
      Iterator iteratorDocWireless=docWireless.getDescendants(filter);
      while (iteratorDocWireless.hasNext()) {
        Element e=(Element)iteratorDocWireless.next();
        String classname=e.getAttributeValue("String_Node_Str");
        if (classname != null) {
          if (classname.equals("String_Node_Str")) {
            micaboard=(Element)e.clone();
            break;
          }
        }
      }
      if (micaboard == null) {
        throw new Exception("String_Node_Str" + micaboardFile);
      }
      Iterator iteratorMicaBoard=micaboard.getDescendants(filter);
      while (iteratorMicaBoard.hasNext()) {
        Element e=(Element)iteratorMicaBoard.next();
        String classname=e.getAttributeValue("String_Node_Str");
        if (classname != null) {
          if (classname.equals("String_Node_Str")) {
            root=e;
          }
 else           if (classname.equals("String_Node_Str")) {
            director=e;
          }
        }
      }
      if (root == null) {
        throw new Exception("String_Node_Str" + micaboardFile);
      }
      if (director == null) {
        throw new Exception("String_Node_Str" + micaboardFile);
      }
    }
 catch (    Exception e) {
      System.err.println("String_Node_Str" + e);
      e.printStackTrace();
    }
    Element rootWireless=new Element("String_Node_Str");
    rootWireless.setAttribute("String_Node_Str",componentName);
    rootWireless.setAttribute("String_Node_Str","String_Node_Str");
    Element wirelessDirector=new Element("String_Node_Str");
    wirelessDirector.setAttribute("String_Node_Str","String_Node_Str");
    wirelessDirector.setAttribute("String_Node_Str","String_Node_Str");
    rootWireless.addContent(wirelessDirector);
    rootWireless.addContent(micaboard);
    doc=new Document(rootWireless,plot);
  }
 else {
    root=new Element("String_Node_Str");
    root.setAttribute("String_Node_Str",componentName);
    root.setAttribute("String_Node_Str","String_Node_Str");
    doc=new Document(root,plot);
    director=new Element("String_Node_Str");
    director.setAttribute("String_Node_Str","String_Node_Str");
    director.setAttribute("String_Node_Str","String_Node_Str");
    root.addContent(director);
  }
  Element pflags=new Element("String_Node_Str");
  pflags.setAttribute("String_Node_Str","String_Node_Str");
  pflags.setAttribute("String_Node_Str","String_Node_Str");
  pflags.setAttribute("String_Node_Str",opts.trim());
  if (director == null) {
    throw new InternalErrorException("String_Node_Str");
  }
 else {
    director.addContent(pflags);
  }
  Element destinationDirectory=new Element("String_Node_Str");
  destinationDirectory.setAttribute("String_Node_Str","String_Node_Str");
  destinationDirectory.setAttribute("String_Node_Str","String_Node_Str");
  destinationDirectory.setAttribute("String_Node_Str",directorOutputDir);
  director.addContent(destinationDirectory);
  Element annotation=new Element("String_Node_Str");
  annotation.setAttribute("String_Node_Str","String_Node_Str");
  annotation.setAttribute("String_Node_Str","String_Node_Str");
  if (root == null) {
    throw new InternalErrorException("String_Node_Str");
  }
 else {
    root.addContent(annotation);
  }
  Element text=new Element("String_Node_Str");
  text.setAttribute("String_Node_Str","String_Node_Str");
  text.setAttribute("String_Node_Str","String_Node_Str");
  text.setAttribute("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  annotation.addContent(text);
  Element location=new Element("String_Node_Str");
  location.setAttribute("String_Node_Str","String_Node_Str");
  location.setAttribute("String_Node_Str","String_Node_Str");
  location.setAttribute("String_Node_Str","String_Node_Str");
  annotation.addContent(location);
  readLinks();
  Enumeration enumeration=_componentFileTable.elements();
  while (enumeration.hasMoreElements()) {
    _ComponentFile componentFile=(_ComponentFile)enumeration.nextElement();
    Element entity=new Element("String_Node_Str");
    entity.setAttribute("String_Node_Str",componentFile.getName());
    entity.setAttribute("String_Node_Str",componentFile.getClassName());
    root.addContent(entity);
  }
  for (int i=1; i <= _relations.currentCount(); i++) {
    Element relation=new Element("String_Node_Str");
    relation.setAttribute("String_Node_Str","String_Node_Str" + i);
    relation.setAttribute("String_Node_Str","String_Node_Str");
    root.addContent(relation);
  }
  for (int i=0; i < _linkList.size(); i++) {
    Element xmlLink=new Element("String_Node_Str");
    _Link link=(_Link)_linkList.get(i);
    String fromType;
    String fromName;
    if (link.from instanceof Port) {
      fromType="String_Node_Str";
      Port port=(Port)link.from;
      fromName=port.getContainer().getName() + "String_Node_Str" + port.getName();
    }
 else     if (link.from instanceof Relation) {
      fromType="String_Node_Str";
      Relation relation=(Relation)link.from;
      fromName=relation.getName();
    }
 else {
      throw new InternalErrorException("String_Node_Str" + "String_Node_Str");
    }
    String toType;
    String toName;
    if (link.to instanceof Port) {
      toType="String_Node_Str";
      Port port=(Port)link.to;
      toName=port.getContainer().getName() + "String_Node_Str" + port.getName();
    }
 else     if (link.to instanceof Relation) {
      toType="String_Node_Str";
      Relation relation=(Relation)link.to;
      toName=relation.getName();
    }
 else {
      throw new InternalErrorException("String_Node_Str" + "String_Node_Str");
    }
    if (fromType.equals("String_Node_Str") && toType.equals("String_Node_Str")) {
      fromType+="String_Node_Str";
      toType+="String_Node_Str";
    }
    xmlLink.setAttribute(fromType,fromName);
    xmlLink.setAttribute(toType,toName);
    root.addContent(xmlLink);
  }
  try {
    FileOutputStream out=null;
    if (outputFile != null) {
      out=new FileOutputStream(outputFile);
    }
    XMLOutputter serializer=new XMLOutputter(Format.getPrettyFormat());
    Format format=serializer.getFormat();
    format.setOmitEncoding(true);
    format.setLineSeparator("String_Node_Str");
    serializer.setFormat(format);
    if (out != null) {
      serializer.output(doc,out);
      out.flush();
      out.close();
    }
 else {
      serializer.output(doc,System.out);
    }
  }
 catch (  IOException e) {
    System.err.println(e);
  }
}

Fixed version (ground truth):
/** 
 * Generate the .moml file for this nesC application.
 * @param componentName The name of the component (no suffix).
 * @param outputFile The file to generate.
 * @param directorOutputDir The output directory to pass to thePtinyOSDirector.
 * @param opts The compiler options (PFLAGS) to pass to thePtinyOSDirector.
 * @param micaboardFile Path to the MoML file that contains theWireless wrapper.  Null if wrapper should not be generated.
 * @exception IllegalActionException If there is a problem creatingan interface IOport or connection.
 * @exception NameDuplicationException If there is a problem creatingan interface IOport or connection.
 */
public void generatePtinyOSModel(String componentName,String outputFile,String directorOutputDir,String opts,String micaboardFile) throws IllegalActionException, NameDuplicationException {
  Element root=null;
  Element director=null;
  DocType plot=new DocType("String_Node_Str","String_Node_Str","String_Node_Str");
  Document doc=null;
  if (micaboardFile != null) {
    Element micaboard=null;
    try {
      SAXBuilder saxbuilder=new SAXBuilder();
      Document docWireless=saxbuilder.build(new File(micaboardFile));
      Filter filter=new ContentFilter(ContentFilter.ELEMENT);
      Iterator iteratorDocWireless=docWireless.getDescendants(filter);
      while (iteratorDocWireless.hasNext()) {
        Element e=(Element)iteratorDocWireless.next();
        String classname=e.getAttributeValue("String_Node_Str");
        if (classname != null) {
          if (classname.equals("String_Node_Str")) {
            micaboard=(Element)e.clone();
            break;
          }
        }
      }
      if (micaboard == null) {
        throw new Exception("String_Node_Str" + micaboardFile);
      }
      Iterator iteratorMicaBoard=micaboard.getDescendants(filter);
      while (iteratorMicaBoard.hasNext()) {
        Element e=(Element)iteratorMicaBoard.next();
        String classname=e.getAttributeValue("String_Node_Str");
        if (classname != null) {
          if (classname.equals("String_Node_Str")) {
            root=e;
          }
 else           if (classname.equals("String_Node_Str")) {
            director=e;
          }
        }
      }
      if (root == null) {
        throw new Exception("String_Node_Str" + micaboardFile);
      }
      if (director == null) {
        throw new Exception("String_Node_Str" + micaboardFile);
      }
    }
 catch (    Exception e) {
      System.err.println("String_Node_Str" + e);
      e.printStackTrace();
    }
    Element rootWireless=new Element("String_Node_Str");
    rootWireless.setAttribute("String_Node_Str",componentName);
    rootWireless.setAttribute("String_Node_Str","String_Node_Str");
    Element wirelessDirector=new Element("String_Node_Str");
    wirelessDirector.setAttribute("String_Node_Str","String_Node_Str");
    wirelessDirector.setAttribute("String_Node_Str","String_Node_Str");
    rootWireless.addContent(wirelessDirector);
    rootWireless.addContent(micaboard);
    doc=new Document(rootWireless,plot);
  }
 else {
    root=new Element("String_Node_Str");
    root.setAttribute("String_Node_Str",componentName);
    root.setAttribute("String_Node_Str","String_Node_Str");
    doc=new Document(root,plot);
    director=new Element("String_Node_Str");
    director.setAttribute("String_Node_Str","String_Node_Str");
    director.setAttribute("String_Node_Str","String_Node_Str");
    root.addContent(director);
  }
  Element pflags=new Element("String_Node_Str");
  pflags.setAttribute("String_Node_Str","String_Node_Str");
  pflags.setAttribute("String_Node_Str","String_Node_Str");
  pflags.setAttribute("String_Node_Str",opts.trim());
  if (director == null) {
    throw new InternalErrorException("String_Node_Str");
  }
 else {
    director.addContent(pflags);
  }
  Element destinationDirectory=new Element("String_Node_Str");
  destinationDirectory.setAttribute("String_Node_Str","String_Node_Str");
  destinationDirectory.setAttribute("String_Node_Str","String_Node_Str");
  destinationDirectory.setAttribute("String_Node_Str",directorOutputDir);
  director.addContent(destinationDirectory);
  Element annotation=new Element("String_Node_Str");
  annotation.setAttribute("String_Node_Str","String_Node_Str");
  annotation.setAttribute("String_Node_Str","String_Node_Str");
  if (root == null) {
    throw new InternalErrorException("String_Node_Str");
  }
 else {
    root.addContent(annotation);
  }
  Element text=new Element("String_Node_Str");
  text.setAttribute("String_Node_Str","String_Node_Str");
  text.setAttribute("String_Node_Str","String_Node_Str");
  text.setAttribute("String_Node_Str","String_Node_Str" + "String_Node_Str" + "String_Node_Str");
  annotation.addContent(text);
  Element location=new Element("String_Node_Str");
  location.setAttribute("String_Node_Str","String_Node_Str");
  location.setAttribute("String_Node_Str","String_Node_Str");
  location.setAttribute("String_Node_Str","String_Node_Str");
  annotation.addContent(location);
  readLinks();
  Enumeration enumeration=_componentFileTable.elements();
  while (enumeration.hasMoreElements()) {
    _ComponentFile componentFile=(_ComponentFile)enumeration.nextElement();
    Element entity=new Element("String_Node_Str");
    entity.setAttribute("String_Node_Str",componentFile.getName());
    entity.setAttribute("String_Node_Str",componentFile.getClassName());
    root.addContent(entity);
  }
  for (int i=1; i <= _relations.currentCount(); i++) {
    Element relation=new Element("String_Node_Str");
    relation.setAttribute("String_Node_Str","String_Node_Str" + i);
    relation.setAttribute("String_Node_Str","String_Node_Str");
    root.addContent(relation);
  }
  for (int i=0; i < _linkList.size(); i++) {
    Element xmlLink=new Element("String_Node_Str");
    _Link link=(_Link)_linkList.get(i);
    String fromType;
    String fromName;
    if (link.from instanceof Port) {
      fromType="String_Node_Str";
      Port port=(Port)link.from;
      fromName=port.getContainer().getName() + "String_Node_Str" + port.getName();
    }
 else     if (link.from instanceof Relation) {
      fromType="String_Node_Str";
      Relation relation=(Relation)link.from;
      fromName=relation.getName();
    }
 else {
      throw new InternalErrorException("String_Node_Str" + "String_Node_Str");
    }
    String toType;
    String toName;
    if (link.to instanceof Port) {
      toType="String_Node_Str";
      Port port=(Port)link.to;
      toName=port.getContainer().getName() + "String_Node_Str" + port.getName();
    }
 else     if (link.to instanceof Relation) {
      toType="String_Node_Str";
      Relation relation=(Relation)link.to;
      toName=relation.getName();
    }
 else {
      throw new InternalErrorException("String_Node_Str" + "String_Node_Str");
    }
    if (fromType.equals("String_Node_Str") && toType.equals("String_Node_Str")) {
      fromType+="String_Node_Str";
      toType+="String_Node_Str";
    }
    xmlLink.setAttribute(fromType,fromName);
    xmlLink.setAttribute(toType,toName);
    root.addContent(xmlLink);
  }
  FileOutputStream out=null;
  try {
    if (outputFile != null) {
      out=new FileOutputStream(outputFile);
    }
    XMLOutputter serializer=new XMLOutputter(Format.getPrettyFormat());
    Format format=serializer.getFormat();
    format.setOmitEncoding(true);
    format.setLineSeparator("String_Node_Str");
    serializer.setFormat(format);
    if (out != null) {
      serializer.output(doc,out);
    }
 else {
      serializer.output(doc,System.out);
    }
  }
 catch (  IOException ex) {
    System.err.println(ex);
  }
 finally {
    if (out != null) {
      try {
        out.flush();
        out.close();
      }
 catch (      IOException ex) {
        ex.printStackTrace();
      }
    }
  }
}