Program: 189859
Project: 189859
Buggy source:
/** 
 * <p>Exports a JTable to a CSV file showing first a dialog to select the file to write.</p>
 * @param parent Parent window
 * @param table Table to export
 * @param separator Separator to use for separating values of a row in the CSV file. If null ',' will be used.
 * @param charset Charset encoding for the file
 * @param columnsToExport Indicates the indexes of the columns to export. All columns will be exported if null
 */
public static void exportTableAsCSV(JComponent parent,JTable table,Character separator,Charset charset,Integer[] columnsToExport){
  String lastPath=NbPreferences.forModule(TableCSVExporter.class).get(LAST_PATH,null);
  final JFileChooser chooser=new JFileChooser(lastPath);
  chooser.setAcceptAllFileFilterUsed(false);
  DialogFileFilter dialogFileFilter=new DialogFileFilter(NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"));
  dialogFileFilter.addExtension("String_Node_Str");
  chooser.addChoosableFileFilter(dialogFileFilter);
  File selectedFile=new File(chooser.getCurrentDirectory(),"String_Node_Str");
  chooser.setSelectedFile(selectedFile);
  int returnFile=chooser.showSaveDialog(null);
  if (returnFile != JFileChooser.APPROVE_OPTION) {
    return;
  }
  File file=chooser.getSelectedFile();
  if (!file.getPath().endsWith("String_Node_Str")) {
    file=new File(file.getPath() + "String_Node_Str");
  }
  String defaultDirectory=file.getParentFile().getAbsolutePath();
  NbPreferences.forModule(TableCSVExporter.class).put(LAST_PATH,defaultDirectory);
  try {
    TableCSVExporter.writeCSVFile(table,file,separator,charset,columnsToExport);
    JOptionPane.showMessageDialog(parent,NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"));
  }
 catch (  IOException ex) {
    JOptionPane.showMessageDialog(parent,NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"),NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"),JOptionPane.ERROR_MESSAGE);
  }
}

Fixed version (ground truth):
/** 
 * <p>Exports a JTable to a CSV file showing first a dialog to select the file to write.</p>
 * @param parent Parent window
 * @param table Table to export
 * @param separator Separator to use for separating values of a row in the CSV file. If null ',' will be used.
 * @param charset Charset encoding for the file
 * @param columnsToExport Indicates the indexes of the columns to export. All columns will be exported if null
 */
public static void exportTableAsCSV(JComponent parent,JTable table,Character separator,Charset charset,Integer[] columnsToExport,String fileName){
  String lastPath=NbPreferences.forModule(TableCSVExporter.class).get(LAST_PATH,null);
  final JFileChooser chooser=new JFileChooser(lastPath);
  chooser.setAcceptAllFileFilterUsed(false);
  DialogFileFilter dialogFileFilter=new DialogFileFilter(NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"));
  dialogFileFilter.addExtension("String_Node_Str");
  chooser.addChoosableFileFilter(dialogFileFilter);
  File selectedFile=new File(chooser.getCurrentDirectory(),fileName);
  chooser.setSelectedFile(selectedFile);
  int returnFile=chooser.showSaveDialog(null);
  if (returnFile != JFileChooser.APPROVE_OPTION) {
    return;
  }
  File file=chooser.getSelectedFile();
  if (!file.getPath().endsWith("String_Node_Str")) {
    file=new File(file.getPath() + "String_Node_Str");
  }
  String defaultDirectory=file.getParentFile().getAbsolutePath();
  NbPreferences.forModule(TableCSVExporter.class).put(LAST_PATH,defaultDirectory);
  try {
    TableCSVExporter.writeCSVFile(table,file,separator,charset,columnsToExport);
    JOptionPane.showMessageDialog(parent,NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"));
  }
 catch (  IOException ex) {
    JOptionPane.showMessageDialog(parent,NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"),NbBundle.getMessage(TableCSVExporter.class,"String_Node_Str"),JOptionPane.ERROR_MESSAGE);
  }
}