Source:
<code>public TableExportButton(JTable table) { super(Constant.messages.getString("export.button.name")); setTable(table); super.setIcon(new ImageIcon(TableExportButton.class.getResource("/resource/icon/16/115.png"))); super.addActionListener((new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { WritableFileChooser chooser = new WritableFileChooser(); chooser.setSelectedFile(new File(Constant.messages.getString("export.button.default.filename"))); if (chooser.showSaveDialog(View.getSingleton().getMainFrame()) == WritableFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().toString(); if (!file.endsWith(".csv")) { file += ".csv"; } try (CSVPrinter pw = new CSVPrinter( Files.newBufferedWriter(chooser.getSelectedFile().toPath(), StandardCharsets.UTF_8), CSVFormat.DEFAULT)) { pw.printRecord(getColumnNames(getTable())); int rowCount = getTable().getRowCount(); int colCount = getTable().getColumnCount(); for (int row = 0; row < rowCount; row++) { List<Object> valueOfRow = new ArrayList<Object>(); for (int col = 0; col < colCount; col++) { <START> String value = getTable().getValueAt(row, col) == null ? "" : getTable().getValueAt(row, col).toString(); <END> valueOfRow.add(value); } pw.printRecord(valueOfRow); } JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(), Constant.messages.getString("export.button.success")); } catch (Exception ex) { JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(), Constant.messages.getString("export.button.error") + "\n" + ex.getMessage()); LOGGER.error("Export Failed: " + ex.getMessage(), ex); } } } })); }</code><technical_language>Worth tweaking this call getValueAt once. delay null check for statement</technical_language>

Target:
public TableExportButton(JTable table) { super(Constant.messages.getString("export.button.name")); setTable(table); super.setIcon(new ImageIcon(TableExportButton.class.getResource("/resource/icon/16/115.png"))); super.addActionListener((new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { WritableFileChooser chooser = new WritableFileChooser(); chooser.setSelectedFile(new File(Constant.messages.getString("export.button.default.filename"))); if (chooser.showSaveDialog(View.getSingleton().getMainFrame()) == WritableFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().toString(); if (!file.endsWith(".csv")) { file += ".csv"; } try (CSVPrinter pw = new CSVPrinter( Files.newBufferedWriter(chooser.getSelectedFile().toPath(), StandardCharsets.UTF_8), CSVFormat.DEFAULT)) { pw.printRecord(getColumnNames()); int rowCount = getTable().getRowCount(); int colCount = getTable().getColumnCount(); for (int row = 0; row < rowCount; row++) { List<Object> valueOfRow = new ArrayList<Object>(); for (int col = 0; col < colCount; col++) { Object value = getTable().getValueAt(row, col); value = value == null ? "" : value; valueOfRow.add(value.toString()); } pw.printRecord(valueOfRow); } JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(), Constant.messages.getString("export.button.success")); } catch (Exception ex) { JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(), Constant.messages.getString("export.button.error") + "\n" + ex.getMessage()); LOGGER.error("Export Failed: " + ex.getMessage(), ex); } } } })); }