Program: 129757
Project: 129757
Buggy source:
/** 
 * Main Fields addControls.
 */
@Override protected void addFieldsListeners(){
  fileFieldXml.addSelectionListener(new SelectionListener(){
    public void widgetSelected(    SelectionEvent event){
      if (fileFieldXml.getResult() == null) {
        return;
      }
      String text=fileFieldXml.getText();
      if (isContextMode()) {
        ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(),true);
        text=TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType,text));
      }
      File file=new File(text);
      if (file.exists()) {
        if (file.exists()) {
          if (XmlUtil.isXSDFile(text)) {
            List<ATreeNode> treeNodes=new ArrayList<ATreeNode>();
            try {
              XSDSchema xsdSchema=updateXSDSchema(text);
              List<ATreeNode> list=updateRootNodes(xsdSchema,true);
              if (list.size() > 1) {
                RootNodeSelectDialog dialog=new RootNodeSelectDialog(null,list);
                if (dialog.open() == IDialogConstants.OK_ID) {
                  ATreeNode selectedNode=dialog.getSelectedNode();
                  valid=treePopulator.populateTree(xsdSchema,selectedNode,treeNodes);
                  if (treeNodes.size() > 0) {
                    treeNode=treeNodes.get(0);
                  }
                }
 else {
                  return;
                }
              }
 else {
                valid=treePopulator.populateTree(xsdSchema,list.get(0),treeNodes);
                if (treeNodes.size() > 0) {
                  treeNode=treeNodes.get(0);
                }
              }
            }
 catch (            Exception ex) {
              ExceptionHandler.process(ex);
            }
            XmlFileWizard wizard=((XmlFileWizard)getPage().getWizard());
            wizard.setRootNodes(treeNodes);
            wizard.setTreeRootNode(treeNode);
            List<FOXTreeNode> nodeList=getCorrespondingFoxTreeNodes(treeNode,true);
            if (nodeList.size() > 0) {
              FOXTreeNode foxTreeNode=nodeList.get(0);
              EList root=getConnection().getRoot();
              if (root == null)               return;
              XMLFileNode xmlFileNode=ConnectionFactory.eINSTANCE.createXMLFileNode();
              String currentPath="String_Node_Str" + foxTreeNode.getLabel();
              xmlFileNode.setXMLPath(currentPath);
              xmlFileNode.setRelatedColumn(foxTreeNode.getColumnLabel());
              xmlFileNode.setAttribute(foxTreeNode.isMain() ? "String_Node_Str" : "String_Node_Str");
              xmlFileNode.setDefaultValue(foxTreeNode.getDefaultValue());
              xmlFileNode.setType(foxTreeNode.getDataType());
              XMLFileNode originalXmlNode=null;
              if (root.size() > 0) {
                originalXmlNode=(XMLFileNode)root.get(0);
              }
              if (originalXmlNode != null && !currentPath.equals(originalXmlNode.getXMLPath())) {
                wizard.setXsdRootChange(true);
              }
 else {
                wizard.setXsdRootChange(false);
              }
              root.clear();
              root.add(xmlFileNode);
            }
          }
 else {
            valid=treePopulator.populateTree(text,treeNode);
          }
        }
      }
    }
    public void widgetDefaultSelected(    SelectionEvent e){
    }
  }
);
  fileFieldXml.addModifyListener(new ModifyListener(){
    public void modifyText(    final ModifyEvent e){
      String text=fileFieldXml.getText();
      if (isContextMode()) {
        ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(),true);
        text=TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType,text));
      }
      if (getConnection().getXmlFilePath() != null && !getConnection().getXmlFilePath().equals(text)) {
        getConnection().getLoop().clear();
        xsdPathChanged=true;
      }
 else {
        xsdPathChanged=false;
      }
      getConnection().setXmlFilePath(PathUtils.getPortablePath(fileFieldXml.getText()));
      XmlFileWizard wizard=((XmlFileWizard)getPage().getWizard());
      wizard.setTreeRootNode(treeNode);
      BufferedReader in=null;
      File file=null;
      if (tempXmlXsdPath != null && getConnection().getFileContent() != null && getConnection().getFileContent().length > 0 && !isModifing) {
        file=new File(tempXmlXsdPath);
        if (!file.exists()) {
          try {
            file.createNewFile();
          }
 catch (          IOException e2) {
            ExceptionHandler.process(e2);
          }
          FileOutputStream outStream;
          try {
            outStream=new FileOutputStream(file);
            outStream.write(getConnection().getFileContent());
            outStream.close();
          }
 catch (          FileNotFoundException e1) {
            ExceptionHandler.process(e1);
          }
catch (          IOException e3) {
            ExceptionHandler.process(e3);
          }
        }
      }
 else {
        file=new File(text);
      }
      if (!XmlUtil.isXMLFile(file.getPath())) {
        setFileContent(file);
      }
      try {
        Charset guessedCharset=CharsetToolkit.guessEncoding(file,4096);
        String str;
        in=new BufferedReader(new InputStreamReader(new FileInputStream(file),guessedCharset.displayName()));
        while ((str=in.readLine()) != null) {
          if (str.contains("String_Node_Str")) {
            String regex="String_Node_Str";
            Perl5Compiler compiler=new Perl5Compiler();
            Perl5Matcher matcher=new Perl5Matcher();
            Pattern pattern=null;
            try {
              pattern=compiler.compile(regex);
              if (matcher.contains(str,pattern)) {
                MatchResult matchResult=matcher.getMatch();
                if (matchResult != null) {
                  encoding=matchResult.group(1);
                }
              }
            }
 catch (            MalformedPatternException malE) {
              ExceptionHandler.process(malE);
            }
          }
        }
      }
 catch (      Exception ex) {
        String fileStr=text;
        String msgError="String_Node_Str" + "String_Node_Str" + fileStr.replace("String_Node_Str","String_Node_Str") + "String_Node_Str";
        if (ex instanceof FileNotFoundException) {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
 else         if (ex instanceof EOFException) {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
 else         if (ex instanceof IOException) {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
 else {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
        if (!isReadOnly()) {
          updateStatus(IStatus.ERROR,msgError);
        }
      }
 finally {
        try {
          if (in != null) {
            in.close();
          }
        }
 catch (        Exception ex2) {
          ExceptionHandler.process(ex2);
        }
      }
      if (getConnection().getEncoding() == null || "String_Node_Str".equals(getConnection().getEncoding())) {
        getConnection().setEncoding(encoding);
        if (encoding != null && !("String_Node_Str").equals(encoding)) {
          encodingCombo.setText(encoding);
        }
 else {
          encodingCombo.setText("String_Node_Str");
        }
      }
      checkFieldsValue();
      isModifing=true;
    }
  }
);
  encodingCombo.addModifyListener(new ModifyListener(){
    public void modifyText(    final ModifyEvent e){
      getConnection().setEncoding(encodingCombo.getText());
      checkFieldsValue();
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Main Fields addControls.
 */
@Override protected void addFieldsListeners(){
  fileFieldXml.addSelectionListener(new SelectionListener(){
    public void widgetSelected(    SelectionEvent event){
      if (fileFieldXml.getResult() == null) {
        return;
      }
      String text=fileFieldXml.getText();
      if (isContextMode()) {
        ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(),true);
        text=TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType,text));
      }
      File file=new File(text);
      if (file.exists()) {
        if (file.exists()) {
          if (XmlUtil.isXSDFile(text)) {
            List<ATreeNode> treeNodes=new ArrayList<ATreeNode>();
            try {
              XSDSchema xsdSchema=updateXSDSchema(text);
              List<ATreeNode> list=updateRootNodes(xsdSchema,true);
              if (list.size() > 1) {
                RootNodeSelectDialog dialog=new RootNodeSelectDialog(null,list);
                if (dialog.open() == IDialogConstants.OK_ID) {
                  ATreeNode selectedNode=dialog.getSelectedNode();
                  valid=treePopulator.populateTree(xsdSchema,selectedNode,treeNodes);
                  if (treeNodes.size() > 0) {
                    treeNode=treeNodes.get(0);
                  }
                }
 else {
                  return;
                }
              }
 else {
                valid=treePopulator.populateTree(xsdSchema,list.get(0),treeNodes);
                if (treeNodes.size() > 0) {
                  treeNode=treeNodes.get(0);
                }
              }
            }
 catch (            Exception ex) {
              ExceptionHandler.process(ex);
            }
            XmlFileWizard wizard=((XmlFileWizard)getPage().getWizard());
            wizard.setRootNodes(treeNodes);
            wizard.setTreeRootNode(treeNode);
            List<FOXTreeNode> nodeList=getCorrespondingFoxTreeNodes(treeNode,true);
            if (nodeList.size() > 0) {
              FOXTreeNode foxTreeNode=nodeList.get(0);
              EList root=getConnection().getRoot();
              if (root == null)               return;
              XMLFileNode xmlFileNode=ConnectionFactory.eINSTANCE.createXMLFileNode();
              String currentPath="String_Node_Str" + foxTreeNode.getLabel();
              xmlFileNode.setXMLPath(currentPath);
              xmlFileNode.setRelatedColumn(foxTreeNode.getColumnLabel());
              xmlFileNode.setAttribute(foxTreeNode.isMain() ? "String_Node_Str" : "String_Node_Str");
              xmlFileNode.setDefaultValue(foxTreeNode.getDefaultValue());
              xmlFileNode.setType(foxTreeNode.getDataType());
              XMLFileNode originalXmlNode=null;
              if (root.size() > 0) {
                originalXmlNode=(XMLFileNode)root.get(0);
              }
              if (originalXmlNode != null && !currentPath.equals(originalXmlNode.getXMLPath())) {
                wizard.setXsdRootChange(true);
              }
 else {
                wizard.setXsdRootChange(false);
              }
              root.clear();
              root.add(xmlFileNode);
            }
          }
 else {
            valid=treePopulator.populateTree(text,treeNode);
          }
        }
        checkFieldsValue();
      }
    }
    public void widgetDefaultSelected(    SelectionEvent e){
    }
  }
);
  fileFieldXml.addModifyListener(new ModifyListener(){
    public void modifyText(    final ModifyEvent e){
      String text=fileFieldXml.getText();
      if (isContextMode()) {
        ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(),true);
        text=TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType,text));
      }
      if (getConnection().getXmlFilePath() != null && !getConnection().getXmlFilePath().equals(text)) {
        getConnection().getLoop().clear();
        xsdPathChanged=true;
      }
 else {
        xsdPathChanged=false;
      }
      getConnection().setXmlFilePath(PathUtils.getPortablePath(fileFieldXml.getText()));
      XmlFileWizard wizard=((XmlFileWizard)getPage().getWizard());
      wizard.setTreeRootNode(treeNode);
      BufferedReader in=null;
      File file=null;
      if (tempXmlXsdPath != null && getConnection().getFileContent() != null && getConnection().getFileContent().length > 0 && !isModifing) {
        file=new File(tempXmlXsdPath);
        if (!file.exists()) {
          try {
            file.createNewFile();
          }
 catch (          IOException e2) {
            ExceptionHandler.process(e2);
          }
          FileOutputStream outStream;
          try {
            outStream=new FileOutputStream(file);
            outStream.write(getConnection().getFileContent());
            outStream.close();
          }
 catch (          FileNotFoundException e1) {
            ExceptionHandler.process(e1);
          }
catch (          IOException e3) {
            ExceptionHandler.process(e3);
          }
        }
      }
 else {
        file=new File(text);
      }
      if (!XmlUtil.isXMLFile(file.getPath())) {
        setFileContent(file);
      }
      try {
        Charset guessedCharset=CharsetToolkit.guessEncoding(file,4096);
        String str;
        in=new BufferedReader(new InputStreamReader(new FileInputStream(file),guessedCharset.displayName()));
        while ((str=in.readLine()) != null) {
          if (str.contains("String_Node_Str")) {
            String regex="String_Node_Str";
            Perl5Compiler compiler=new Perl5Compiler();
            Perl5Matcher matcher=new Perl5Matcher();
            Pattern pattern=null;
            try {
              pattern=compiler.compile(regex);
              if (matcher.contains(str,pattern)) {
                MatchResult matchResult=matcher.getMatch();
                if (matchResult != null) {
                  encoding=matchResult.group(1);
                }
              }
            }
 catch (            MalformedPatternException malE) {
              ExceptionHandler.process(malE);
            }
          }
        }
      }
 catch (      Exception ex) {
        String fileStr=text;
        String msgError="String_Node_Str" + "String_Node_Str" + fileStr.replace("String_Node_Str","String_Node_Str") + "String_Node_Str";
        if (ex instanceof FileNotFoundException) {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
 else         if (ex instanceof EOFException) {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
 else         if (ex instanceof IOException) {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
 else {
          msgError=msgError + Messages.getString("String_Node_Str");
        }
        if (!isReadOnly()) {
          updateStatus(IStatus.ERROR,msgError);
        }
      }
 finally {
        try {
          if (in != null) {
            in.close();
          }
        }
 catch (        Exception ex2) {
          ExceptionHandler.process(ex2);
        }
      }
      if (getConnection().getEncoding() == null || "String_Node_Str".equals(getConnection().getEncoding())) {
        getConnection().setEncoding(encoding);
        if (encoding != null && !("String_Node_Str").equals(encoding)) {
          encodingCombo.setText(encoding);
        }
 else {
          encodingCombo.setText("String_Node_Str");
        }
      }
      checkFieldsValue();
      isModifing=true;
    }
  }
);
  encodingCombo.addModifyListener(new ModifyListener(){
    public void modifyText(    final ModifyEvent e){
      getConnection().setEncoding(encodingCombo.getText());
      checkFieldsValue();
    }
  }
);
}