Program: 120780
Project: 120780
Buggy source:
/** 
 * Generate the code for the process given to the constructor.
 * @return the generated code
 * @throws CodeGeneratorException if an error occurs during Code Generation
 */
@SuppressWarnings("String_Node_Str") public String generateProcessCode() throws CodeGeneratorException {
  StringBuffer componentsCode=new StringBuffer();
  long startTimer=System.currentTimeMillis();
  long endTimer=startTimer;
  try {
    while ((!CodeGeneratorEmittersPoolFactory.isInitialized()) && ((endTimer - startTimer) < INIT_TIMEOUT)) {
      Thread.sleep(INIT_PAUSE);
      endTimer=System.currentTimeMillis();
    }
  }
 catch (  InterruptedException e) {
    log.error(e.getMessage(),e);
    throw new CodeGeneratorException(e);
  }
  if ((endTimer - startTimer) > INIT_TIMEOUT) {
    throw new CodeGeneratorException(Messages.getString("String_Node_Str"));
  }
 else {
    Vector headerArgument=new Vector(3);
    headerArgument.add(process);
    headerArgument.add(VersionUtils.getVersion());
    headerArgument.add(exportAsOSGI);
    boolean isCamel=false;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
      ICamelDesignerCoreService camelService=(ICamelDesignerCoreService)GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
      if (process != null && process instanceof IProcess2) {
        IProcess2 process2=(IProcess2)process;
        if (camelService.isInstanceofCamelRoutes(process2.getProperty().getItem())) {
          isCamel=true;
        }
      }
    }
    if (isCamel) {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ROUTE,headerArgument));
    }
 else {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER,headerArgument));
    }
    if (isCamel) {
      if ((processTree.getSubTrees() != null) && (processTree.getSubTrees().size() > 0)) {
        boolean displayMethodSize=isMethodSizeNeeded();
        NodesSubTree lastSubtree=null;
        boolean generateHeaders=true;
        boolean isFirstRoute=true;
        List<NodesSubTree> nodeSubTreeList=new ArrayList<NodesSubTree>();
        List<INode> sortedNodeList=new ArrayList<INode>();
        for (        NodesSubTree subTree : processTree.getSubTrees()) {
          lastSubtree=subTree;
          if (generateHeaders) {
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER_ROUTE,subTree));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.CAMEL_HEADER,headerArgument));
            generateHeaders=false;
          }
          INode subProcessStartNode=subTree.getRootNode().getSubProcessStartNode(true);
          String startNodeName=subProcessStartNode.getComponent().getName();
          IElementParameter family=subProcessStartNode.getElementParameter("String_Node_Str");
          if (subProcessStartNode.isStart() && null != family && "String_Node_Str".equals(family.getValue())) {
            nodeSubTreeList.add(subTree);
          }
 else           if ("String_Node_Str".equals(startNodeName)) {
          }
 else {
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.MAIN,null,ETypeGen.CAMEL));
            componentsCode.append("String_Node_Str");
          }
        }
        for (        NodesSubTree subTree : nodeSubTreeList) {
          lastSubtree=subTree;
          componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.MAIN,null,ETypeGen.CAMEL));
          componentsCode.append("String_Node_Str");
        }
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.CAMEL_FOOTER,headerArgument));
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER_ROUTE,lastSubtree));
      }
    }
 else {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ADDITIONAL,headerArgument));
      if ((processTree.getSubTrees() != null) && (processTree.getSubTrees().size() > 0)) {
        boolean displayMethodSize=isMethodSizeNeeded();
        for (        NodesSubTree subTree : processTree.getSubTrees()) {
          subTree.setMethodSizeNeeded(displayMethodSize);
          if (!subTree.isMergeSubTree()) {
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER,subTree));
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.BEGIN,null));
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.MAIN,null));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN,subTree.getRootNode()));
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.END,null));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER,subTree));
          }
 else {
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER,subTree));
            componentsCode.append(generateComponentsCode(subTree,subTree.getMergeNode(),ECodePart.BEGIN,null));
            List<INode> sortedMergeBranchStarts=subTree.getSortedMergeBranchStarts();
            for (            INode startNode : sortedMergeBranchStarts) {
              componentsCode.append(generateComponentsCode(subTree,startNode,ECodePart.BEGIN,null));
              componentsCode.append(generateComponentsCode(subTree,startNode,ECodePart.MAIN,null));
              componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN,subTree.getRootNode()));
              componentsCode.append(generateComponentsCode(subTree,startNode,ECodePart.END,null));
            }
            componentsCode.append(generateComponentsCode(subTree,subTree.getMergeNode(),ECodePart.END,null));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER,subTree));
          }
        }
      }
    }
    Vector footerArgument=new Vector(2);
    footerArgument.add(process);
    footerArgument.add(processTree.getRootNodes());
    if (isCamel)     componentsCode.append(generateTypedComponentCode(EInternalTemplate.FOOTER_ROUTE,footerArgument));
 else     componentsCode.append(generateTypedComponentCode(EInternalTemplate.FOOTER,footerArgument));
    componentsCode.append(generateTypedComponentCode(EInternalTemplate.PROCESSINFO,componentsCode.length()));
    return componentsCode.toString();
  }
}

Fixed version (ground truth):
/** 
 * Generate the code for the process given to the constructor.
 * @return the generated code
 * @throws CodeGeneratorException if an error occurs during Code Generation
 */
@Override @SuppressWarnings("String_Node_Str") public String generateProcessCode() throws CodeGeneratorException {
  StringBuffer componentsCode=new StringBuffer();
  long startTimer=System.currentTimeMillis();
  long endTimer=startTimer;
  try {
    while ((!CodeGeneratorEmittersPoolFactory.isInitialized()) && ((endTimer - startTimer) < INIT_TIMEOUT)) {
      Thread.sleep(INIT_PAUSE);
      endTimer=System.currentTimeMillis();
    }
  }
 catch (  InterruptedException e) {
    log.error(e.getMessage(),e);
    throw new CodeGeneratorException(e);
  }
  if ((endTimer - startTimer) > INIT_TIMEOUT) {
    throw new CodeGeneratorException(Messages.getString("String_Node_Str"));
  }
 else {
    Vector headerArgument=new Vector(3);
    headerArgument.add(process);
    headerArgument.add(VersionUtils.getVersion());
    headerArgument.add(exportAsOSGI);
    boolean isCamel=false;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
      ICamelDesignerCoreService camelService=(ICamelDesignerCoreService)GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
      if (process != null && process instanceof IProcess2) {
        IProcess2 process2=(IProcess2)process;
        if (camelService.isInstanceofCamelRoutes(process2.getProperty().getItem())) {
          isCamel=true;
        }
      }
    }
    if (isCamel) {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ROUTE,headerArgument));
    }
 else {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER,headerArgument));
    }
    if (isCamel) {
      if ((processTree.getSubTrees() != null) && (processTree.getSubTrees().size() > 0)) {
        boolean displayMethodSize=isMethodSizeNeeded();
        NodesSubTree lastSubtree=null;
        boolean generateHeaders=true;
        boolean isFirstRoute=true;
        List<NodesSubTree> nodeSubTreeList=new ArrayList<NodesSubTree>();
        List<INode> sortedNodeList=new ArrayList<INode>();
        for (        NodesSubTree subTree : processTree.getSubTrees()) {
          lastSubtree=subTree;
          if (generateHeaders) {
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER_ROUTE,subTree));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.CAMEL_HEADER,headerArgument));
            generateHeaders=false;
          }
          INode subProcessStartNode=subTree.getRootNode().getSubProcessStartNode(true);
          String startNodeName=subProcessStartNode.getComponent().getName();
          IElementParameter family=subProcessStartNode.getElementParameter("String_Node_Str");
          if (subProcessStartNode.isStart() && null != family && "String_Node_Str".equals(family.getValue())) {
            nodeSubTreeList.add(subTree);
          }
 else           if ("String_Node_Str".equals(startNodeName)) {
          }
 else {
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.MAIN,null,ETypeGen.CAMEL));
            componentsCode.append("String_Node_Str");
          }
        }
        for (        NodesSubTree subTree : nodeSubTreeList) {
          lastSubtree=subTree;
          componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.MAIN,null,ETypeGen.CAMEL));
          componentsCode.append("String_Node_Str");
        }
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.CAMEL_FOOTER,headerArgument));
        componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER_ROUTE,lastSubtree));
      }
    }
 else {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.HEADER_ADDITIONAL,headerArgument));
      if ((processTree.getSubTrees() != null) && (processTree.getSubTrees().size() > 0)) {
        boolean displayMethodSize=isMethodSizeNeeded();
        for (        NodesSubTree subTree : processTree.getSubTrees()) {
          subTree.setMethodSizeNeeded(displayMethodSize);
          if (!subTree.isMergeSubTree()) {
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER,subTree));
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.BEGIN,null));
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.MAIN,null));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN,subTree.getRootNode()));
            componentsCode.append(generateComponentsCode(subTree,subTree.getRootNode(),ECodePart.END,null));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER,subTree));
          }
 else {
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_HEADER,subTree));
            componentsCode.append(generateComponentsCode(subTree,subTree.getMergeNode(),ECodePart.BEGIN,null));
            List<INode> sortedMergeBranchStarts=subTree.getSortedMergeBranchStarts();
            for (            INode startNode : sortedMergeBranchStarts) {
              componentsCode.append(generateComponentsCode(subTree,startNode,ECodePart.BEGIN,null));
              componentsCode.append(generateComponentsCode(subTree,startNode,ECodePart.MAIN,null));
              componentsCode.append(generateTypedComponentCode(EInternalTemplate.PART_ENDMAIN,subTree.getRootNode()));
              componentsCode.append(generateComponentsCode(subTree,startNode,ECodePart.END,null));
            }
            componentsCode.append(generateComponentsCode(subTree,subTree.getMergeNode(),ECodePart.END,null));
            componentsCode.append(generateTypedComponentCode(EInternalTemplate.SUBPROCESS_FOOTER,subTree));
          }
        }
      }
    }
    Vector footerArgument=new Vector(2);
    footerArgument.add(process);
    footerArgument.add(processTree.getRootNodes());
    if (isCamel) {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.FOOTER_ROUTE,footerArgument));
    }
 else {
      componentsCode.append(generateTypedComponentCode(EInternalTemplate.FOOTER,footerArgument));
    }
    componentsCode.append(generateTypedComponentCode(EInternalTemplate.PROCESSINFO,componentsCode.length()));
    return componentsCode.toString();
  }
}