Program: 133346
Project: 133346
Buggy source:
/** 
 * This operation ensures that the MOOSEFileHandler can create a MOOSE input file from a set of incoming TreeComposites.
 */
@Test public void checkWritingInputFileFromTree(){
  String separator=System.getProperty("String_Node_Str");
  String userDir=System.getProperty("String_Node_Str") + separator + "String_Node_Str"+ separator+ "String_Node_Str";
  String filePath=userDir + separator + "String_Node_Str";
  String outputFilePath=userDir + separator + "String_Node_Str";
  String refFilePath=userDir + separator + "String_Node_Str";
  File outputFile=null;
  MOOSEFileHandler handler=new MOOSEFileHandler();
  TreeComposite adaptivity=null, indicators=null;
  TreeComposite analyticalIndicator=null, fluxJumpIndicator=null;
  TreeComposite function=null, powerHistory=null;
  ArrayList<TreeComposite> blocks=null;
  try {
    blocks=handler.loadYAML(filePath);
  }
 catch (  IOException e1) {
    e1.printStackTrace();
  }
  adaptivity=getTreeByName(blocks,"String_Node_Str");
  indicators=(TreeComposite)adaptivity.getChildExemplars().get(0).clone();
  analyticalIndicator=(TreeComposite)indicators.getChildExemplars().get(1).clone();
  fluxJumpIndicator=(TreeComposite)indicators.getChildExemplars().get(2).clone();
  adaptivity.setNextChild(indicators);
  indicators.setNextChild(analyticalIndicator);
  analyticalIndicator.setActive(true);
  indicators.setNextChild(fluxJumpIndicator);
  adaptivity.setActive(true);
  indicators.setActive(true);
  analyticalIndicator.setActive(true);
  fluxJumpIndicator.setActive(true);
  DataComponent adaptivityData=(DataComponent)adaptivity.getDataNodes().get(0);
  adaptivity.setActiveDataNode(adaptivityData);
  adaptivityData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  adaptivityData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  adaptivityData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  DataComponent analyticalIndicatorsComponent=(DataComponent)analyticalIndicator.getDataNodes().get(0);
  analyticalIndicatorsComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  analyticalIndicatorsComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  DataComponent fluxJumpIndicatorComponent=(DataComponent)fluxJumpIndicator.getDataNodes().get(0);
  fluxJumpIndicatorComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  fluxJumpIndicatorComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  fluxJumpIndicatorComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  function=(TreeComposite)getTreeByName(blocks,"String_Node_Str");
  powerHistory=(TreeComposite)function.getChildExemplars().get(14).clone();
  function.setNextChild(powerHistory);
  powerHistory.setName("String_Node_Str");
  function.setActive(true);
  powerHistory.setActive(true);
  DataComponent powerData=(DataComponent)powerHistory.getDataNodes().get(0);
  powerData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  powerData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  Parameter dataFileParam=new Parameter();
  dataFileParam.setName("String_Node_Str");
  dataFileParam.setDefault("String_Node_Str");
  dataFileParam.setEnabled(true);
  powerData.addEntry(dataFileParam.toEntry());
  handler.dumpInputFile(outputFilePath,blocks);
  outputFile=new File(outputFilePath);
  assertTrue(outputFile.exists());
  int firstHash, lastHash;
  try {
    RandomAccessFile inputFileRAF=new RandomAccessFile(outputFilePath,"String_Node_Str");
    byte[] inputBytes=new byte[(int)inputFileRAF.length()];
    inputFileRAF.read(inputBytes);
    String inputString=new String(inputBytes);
    String[] inputArray=inputString.split("String_Node_Str");
    inputString="String_Node_Str";
    boolean hasComment=false;
    for (    String line : inputArray) {
      hasComment=!(line.lastIndexOf("String_Node_Str") == -1);
      if (hasComment) {
        firstHash=line.trim().indexOf("String_Node_Str");
        lastHash=line.trim().lastIndexOf("String_Node_Str");
        if (firstHash == 0 && firstHash == lastHash) {
        }
 else {
          line=line.substring(0,line.lastIndexOf("String_Node_Str"));
          line=line.replaceAll("String_Node_Str","String_Node_Str");
        }
        if (line.endsWith("String_Node_Str")) {
          line+="String_Node_Str";
        }
      }
      inputString+=line + "String_Node_Str";
    }
    RandomAccessFile refFileRAF=new RandomAccessFile(refFilePath,"String_Node_Str");
    byte[] refBytes=new byte[(int)refFileRAF.length()];
    refFileRAF.read(refBytes);
    String refString=new String(refBytes);
    System.out.println(inputString);
    assertEquals(refString,inputString);
    inputFileRAF.close();
    refFileRAF.close();
    outputFile.deleteOnExit();
  }
 catch (  IOException e) {
    e.printStackTrace();
    fail();
  }
  return;
}

Fixed version (ground truth):
/** 
 * This operation ensures that the MOOSEFileHandler can create a MOOSE input file from a set of incoming TreeComposites.
 */
@Test public void checkWritingInputFileFromTree(){
  String separator=System.getProperty("String_Node_Str");
  String userDir=System.getProperty("String_Node_Str") + separator + "String_Node_Str"+ separator+ "String_Node_Str";
  String filePath=userDir + separator + "String_Node_Str";
  String outputFilePath=userDir + separator + "String_Node_Str";
  String refFilePath=userDir + separator + "String_Node_Str";
  File outputFile=null;
  MOOSEFileHandler handler=new MOOSEFileHandler();
  TreeComposite adaptivity=null, indicators=null;
  TreeComposite analyticalIndicator=null, fluxJumpIndicator=null;
  TreeComposite function=null, powerHistory=null;
  ArrayList<TreeComposite> blocks=null;
  try {
    blocks=handler.loadYAML(filePath);
  }
 catch (  IOException e1) {
    e1.printStackTrace();
  }
  adaptivity=getTreeByName(blocks,"String_Node_Str");
  indicators=(TreeComposite)adaptivity.getChildExemplars().get(0).clone();
  analyticalIndicator=(TreeComposite)indicators.getChildExemplars().get(1).clone();
  fluxJumpIndicator=(TreeComposite)indicators.getChildExemplars().get(2).clone();
  adaptivity.setNextChild(indicators);
  indicators.setNextChild(analyticalIndicator);
  analyticalIndicator.setActive(true);
  indicators.setNextChild(fluxJumpIndicator);
  adaptivity.setActive(true);
  indicators.setActive(true);
  analyticalIndicator.setActive(true);
  fluxJumpIndicator.setActive(true);
  DataComponent adaptivityData=(DataComponent)adaptivity.getDataNodes().get(0);
  adaptivity.setActiveDataNode(adaptivityData);
  adaptivityData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  adaptivityData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  adaptivityData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  DataComponent analyticalIndicatorsComponent=(DataComponent)analyticalIndicator.getDataNodes().get(0);
  analyticalIndicatorsComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  analyticalIndicatorsComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  DataComponent fluxJumpIndicatorComponent=(DataComponent)fluxJumpIndicator.getDataNodes().get(0);
  fluxJumpIndicatorComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  fluxJumpIndicatorComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  fluxJumpIndicatorComponent.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  function=(TreeComposite)getTreeByName(blocks,"String_Node_Str");
  powerHistory=(TreeComposite)function.getChildExemplars().get(14).clone();
  function.setNextChild(powerHistory);
  powerHistory.setName("String_Node_Str");
  function.setActive(true);
  powerHistory.setActive(true);
  DataComponent powerData=(DataComponent)powerHistory.getDataNodes().get(0);
  powerData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  powerData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  powerData.retrieveEntry("String_Node_Str").setValue("String_Node_Str");
  powerData.retrieveEntry("String_Node_Str").setTag("String_Node_Str");
  handler.dumpInputFile(outputFilePath,blocks);
  outputFile=new File(outputFilePath);
  assertTrue(outputFile.exists());
  int firstHash, lastHash;
  try {
    RandomAccessFile inputFileRAF=new RandomAccessFile(outputFilePath,"String_Node_Str");
    byte[] inputBytes=new byte[(int)inputFileRAF.length()];
    inputFileRAF.read(inputBytes);
    String inputString=new String(inputBytes);
    String[] inputArray=inputString.split("String_Node_Str");
    inputString="String_Node_Str";
    boolean hasComment=false;
    for (    String line : inputArray) {
      hasComment=!(line.lastIndexOf("String_Node_Str") == -1);
      if (hasComment) {
        firstHash=line.trim().indexOf("String_Node_Str");
        lastHash=line.trim().lastIndexOf("String_Node_Str");
        if (firstHash == 0 && firstHash == lastHash) {
        }
 else {
          line=line.substring(0,line.lastIndexOf("String_Node_Str"));
          line=line.replaceAll("String_Node_Str","String_Node_Str");
        }
        if (line.endsWith("String_Node_Str")) {
          line+="String_Node_Str";
        }
      }
      inputString+=line + "String_Node_Str";
    }
    RandomAccessFile refFileRAF=new RandomAccessFile(refFilePath,"String_Node_Str");
    byte[] refBytes=new byte[(int)refFileRAF.length()];
    refFileRAF.read(refBytes);
    String refString=new String(refBytes);
    System.out.println(inputString);
    assertEquals(refString,inputString);
    inputFileRAF.close();
    refFileRAF.close();
    outputFile.deleteOnExit();
  }
 catch (  IOException e) {
    e.printStackTrace();
    fail();
  }
  return;
}