Program: 123907
Project: 123907
Buggy source:
public void selectOutputXmlTree(OutputXmlTree outputTree){
  if (outputTree != selectedOutputTree) {
    selectedOutputTree=outputTree;
    MetadataTableEditorView outputMetaEditorView=mapperUI.getTabFolderEditors().getOutputMetaEditorView();
    List<IMetadataTable> metadataList=mapperComponent.getMetadataList();
    IMetadataTable table=null;
    for (int i=0; i < metadataList.size(); i++) {
      if (outputTree.getName() != null && outputTree.getName().equals(metadataList.get(i).getTableName())) {
        table=metadataList.get(i);
        break;
      }
    }
    if (outputTree.isErrorReject()) {
      for (      IMetadataColumn column : table.getListColumns()) {
        if (ERROR_REJECT_MESSAGE.equals(column.getLabel()) || ERROR_REJECT_STACK_TRACE.equals(column.getLabel())) {
          column.setCustom(true);
        }
      }
      CustomTableManager.addCustomManagementToTable(mapperUI.getTabFolderEditors().getOutputMetaEditorView(),true);
    }
    if (table != null) {
      MetadataTableEditor editor=new MetadataTableEditor(table,table.getLabel());
      outputMetaEditorView.setMetadataTableEditor(editor);
      editor.setModifiedBeanListenable(outputMetaEditorView.getTableViewerCreator());
      IModifiedBeanListener<IMetadataColumn> columnListener=new IModifiedBeanListener<IMetadataColumn>(){
        public void handleEvent(        ModifiedBeanEvent<IMetadataColumn> event){
          fireCurrentDirectEditApply();
          if (AbstractMetadataTableEditorView.ID_COLUMN_NAME.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              if (treeNode != null) {
                treeNode.setName((String)event.newValue);
                XmlMapUtil.updateXPathAndExpression(copyOfMapData,treeNode,treeNode.getName(),XmlMapUtil.getXPathLength(treeNode.getXpath()),true);
              }
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_TYPE.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              if (treeNode != null) {
                if (treeNode.getType() != null && treeNode.getType().equals(XmlMapUtil.DOCUMENT)) {
                  XmlMapUtil.detachNodeConnections(treeNode,copyOfMapData,true);
                  treeNode.getChildren().clear();
                }
                treeNode.setType((String)event.newValue);
                if (XmlMapUtil.DOCUMENT.equals(event.newValue)) {
                  XmlMapUtil.detachNodeConnections(treeNode,copyOfMapData,true);
                  OutputTreeNode createTreeNode=XmlmapFactory.eINSTANCE.createOutputTreeNode();
                  createTreeNode.setName("String_Node_Str");
                  createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                  createTreeNode.setNodeType(NodeType.ELEMENT);
                  createTreeNode.setXpath(XmlMapUtil.getXPath(treeNode.getXpath(),createTreeNode.getName(),createTreeNode.getNodeType()));
                  createTreeNode.setLoop(true);
                  treeNode.getChildren().add(createTreeNode);
                }
                problemsAnalyser.checkLoopProblems(selectedOutputTree);
                mapperUI.updateStatusBar();
                refreshOutputTreeSchemaEditor(selectedOutputTree);
              }
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_KEY.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              treeNode.setKey((Boolean)event.newValue);
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_PATTERN.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              treeNode.setPattern((String)event.newValue);
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_NULLABLE.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              treeNode.setNullable((Boolean)event.newValue);
            }
          }
        }
      }
;
      editor.addModifiedBeanListener(columnListener);
      editor.addAfterOperationListListener(new IListenableListListener(){
        public void handleEvent(        ListenableListEvent event){
          if (event.type == TYPE.ADDED) {
            EList<OutputTreeNode> nodes=selectedOutputTree.getNodes();
            List<IMetadataColumn> metadataColumns=(List<IMetadataColumn>)event.addedObjects;
            if (event.index != null) {
              int index=event.index;
              for (              IMetadataColumn column : metadataColumns) {
                OutputTreeNode createTreeNode=XmlmapFactory.eINSTANCE.createOutputTreeNode();
                createTreeNode.setName(column.getLabel());
                createTreeNode.setType(column.getTalendType());
                createTreeNode.setNullable(column.isNullable());
                createTreeNode.setPattern(column.getPattern());
                createTreeNode.setXpath(XmlMapUtil.getXPath(selectedOutputTree.getName(),createTreeNode.getName(),createTreeNode.getNodeType()));
                selectedOutputTree.getNodes().add(index,createTreeNode);
                index=index + 1;
              }
            }
          }
 else           if (event.type == TYPE.REMOVED) {
            List<IMetadataColumn> metadataColumns=(List<IMetadataColumn>)event.removedObjects;
            List treeNodeToRemove=new ArrayList();
            for (            IMetadataColumn column : metadataColumns) {
              for (              TreeNode node : selectedOutputTree.getNodes()) {
                if (node.getName() != null && node.getName().equals(column.getLabel())) {
                  XmlMapUtil.detachNodeConnections(node,copyOfMapData,true);
                  treeNodeToRemove.add(node);
                }
              }
            }
            selectedOutputTree.getNodes().removeAll(treeNodeToRemove);
          }
 else           if (event.type == TYPE.SWAPED) {
            List<Integer> listIndexTarget=event.indicesTarget;
            List<Integer> listIndexOrignal=event.indicesOrigin;
            for (int i=0; i < listIndexOrignal.size(); i++) {
              int orignal=listIndexOrignal.get(i);
              int target=listIndexTarget.get(i);
              if (orignal < selectedOutputTree.getNodes().size()) {
                OutputTreeNode tempTreeNode=selectedOutputTree.getNodes().get(orignal);
                selectedOutputTree.getNodes().remove(orignal);
                selectedOutputTree.getNodes().add(target,tempTreeNode);
              }
            }
          }
        }
      }
);
    }
    refreshOutputTreeSchemaEditor(outputTree);
  }
}

Fixed version (ground truth):
public void selectOutputXmlTree(OutputXmlTree outputTree){
  if (outputTree != selectedOutputTree) {
    selectedOutputTree=outputTree;
    MetadataTableEditorView outputMetaEditorView=mapperUI.getTabFolderEditors().getOutputMetaEditorView();
    List<IMetadataTable> metadataList=mapperComponent.getMetadataList();
    IMetadataTable table=null;
    for (int i=0; i < metadataList.size(); i++) {
      if (outputTree.getName() != null && outputTree.getName().equals(metadataList.get(i).getTableName())) {
        table=metadataList.get(i);
        break;
      }
    }
    if (outputTree.isErrorReject()) {
      for (      IMetadataColumn column : table.getListColumns()) {
        if (ERROR_REJECT_MESSAGE.equals(column.getLabel()) || ERROR_REJECT_STACK_TRACE.equals(column.getLabel())) {
          column.setCustom(true);
        }
      }
      CustomTableManager.addCustomManagementToTable(mapperUI.getTabFolderEditors().getOutputMetaEditorView(),true);
    }
    if (table != null) {
      MetadataTableEditor editor=new MetadataTableEditor(table,table.getLabel());
      outputMetaEditorView.setMetadataTableEditor(editor);
      editor.setModifiedBeanListenable(outputMetaEditorView.getTableViewerCreator());
      IModifiedBeanListener<IMetadataColumn> columnListener=new IModifiedBeanListener<IMetadataColumn>(){
        public void handleEvent(        ModifiedBeanEvent<IMetadataColumn> event){
          fireCurrentDirectEditApply();
          if (AbstractMetadataTableEditorView.ID_COLUMN_NAME.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              if (treeNode != null) {
                treeNode.setName((String)event.newValue);
                processColumnNameChanged(treeNode);
              }
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_TYPE.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              if (treeNode != null) {
                if (treeNode.getType() != null && treeNode.getType().equals(XmlMapUtil.DOCUMENT)) {
                  XmlMapUtil.detachNodeConnections(treeNode,copyOfMapData,true);
                  treeNode.getChildren().clear();
                }
                treeNode.setType((String)event.newValue);
                if (XmlMapUtil.DOCUMENT.equals(event.newValue)) {
                  XmlMapUtil.detachNodeConnections(treeNode,copyOfMapData,true);
                  OutputTreeNode createTreeNode=XmlmapFactory.eINSTANCE.createOutputTreeNode();
                  createTreeNode.setName("String_Node_Str");
                  createTreeNode.setType(XmlMapUtil.DEFAULT_DATA_TYPE);
                  createTreeNode.setNodeType(NodeType.ELEMENT);
                  createTreeNode.setXpath(XmlMapUtil.getXPath(treeNode.getXpath(),createTreeNode.getName(),createTreeNode.getNodeType()));
                  createTreeNode.setLoop(true);
                  treeNode.getChildren().add(createTreeNode);
                }
                problemsAnalyser.checkLoopProblems(selectedOutputTree);
                mapperUI.updateStatusBar();
                refreshOutputTreeSchemaEditor(selectedOutputTree);
              }
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_KEY.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              treeNode.setKey((Boolean)event.newValue);
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_PATTERN.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              treeNode.setPattern((String)event.newValue);
            }
          }
 else           if (AbstractMetadataTableEditorView.ID_COLUMN_NULLABLE.equals(event.column.getId())) {
            if (event.index < selectedOutputTree.getNodes().size()) {
              TreeNode treeNode=selectedOutputTree.getNodes().get(event.index);
              treeNode.setNullable((Boolean)event.newValue);
            }
          }
        }
      }
;
      editor.addModifiedBeanListener(columnListener);
      editor.addAfterOperationListListener(new IListenableListListener(){
        public void handleEvent(        ListenableListEvent event){
          if (event.type == TYPE.ADDED) {
            EList<OutputTreeNode> nodes=selectedOutputTree.getNodes();
            List<IMetadataColumn> metadataColumns=(List<IMetadataColumn>)event.addedObjects;
            if (event.index != null) {
              int index=event.index;
              for (              IMetadataColumn column : metadataColumns) {
                OutputTreeNode createTreeNode=XmlmapFactory.eINSTANCE.createOutputTreeNode();
                createTreeNode.setName(column.getLabel());
                createTreeNode.setType(column.getTalendType());
                createTreeNode.setNullable(column.isNullable());
                createTreeNode.setPattern(column.getPattern());
                createTreeNode.setXpath(XmlMapUtil.getXPath(selectedOutputTree.getName(),createTreeNode.getName(),createTreeNode.getNodeType()));
                selectedOutputTree.getNodes().add(index,createTreeNode);
                index=index + 1;
              }
            }
          }
 else           if (event.type == TYPE.REMOVED) {
            List<IMetadataColumn> metadataColumns=(List<IMetadataColumn>)event.removedObjects;
            List treeNodeToRemove=new ArrayList();
            for (            IMetadataColumn column : metadataColumns) {
              for (              TreeNode node : selectedOutputTree.getNodes()) {
                if (node.getName() != null && node.getName().equals(column.getLabel())) {
                  XmlMapUtil.detachNodeConnections(node,copyOfMapData,true);
                  treeNodeToRemove.add(node);
                }
              }
            }
            selectedOutputTree.getNodes().removeAll(treeNodeToRemove);
          }
 else           if (event.type == TYPE.SWAPED) {
            List<Integer> listIndexTarget=event.indicesTarget;
            List<Integer> listIndexOrignal=event.indicesOrigin;
            for (int i=0; i < listIndexOrignal.size(); i++) {
              int orignal=listIndexOrignal.get(i);
              int target=listIndexTarget.get(i);
              if (orignal < selectedOutputTree.getNodes().size()) {
                OutputTreeNode tempTreeNode=selectedOutputTree.getNodes().get(orignal);
                selectedOutputTree.getNodes().remove(orignal);
                selectedOutputTree.getNodes().add(target,tempTreeNode);
              }
            }
          }
        }
      }
);
    }
    refreshOutputTreeSchemaEditor(outputTree);
  }
}