Skip to content

Fix locale-dependent decimal formatting crashes in result tables#108

Open
BioGeek wants to merge 1 commit into
wenbostar:masterfrom
BioGeek:fix-locale-independent-decimal-format
Open

Fix locale-dependent decimal formatting crashes in result tables#108
BioGeek wants to merge 1 commit into
wenbostar:masterfrom
BioGeek:fix-locale-independent-decimal-format

Conversation

@BioGeek

@BioGeek BioGeek commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a locale-dependent decimal formatting bug that can crash PDV result table rendering when the JVM default locale uses a comma as decimal separator.

PDV currently formats numeric values with DecimalFormat, then in several places parses the formatted string back with Double.valueOf(...). Under locales such as German, French, Dutch/Belgian, etc., DecimalFormat("#.0000").format(8.6407) returns 8,6407, but Double.valueOf("8,6407") throws NumberFormatException.

This was observed while opening InstaNovo results in PDV 2.4.0, but the root cause is not specific to InstaNovo. The same pattern exists in shared table models and other import/export/display paths.

Steps To Reproduce

  1. Start PDV 2.4.0 with a locale that uses comma decimal separators, for example:
java -Duser.language=de -Duser.country=DE -jar PDV-2.4.0.jar
  1. Open the De Novo import dialog.
  2. Select an InstaNovo CSV result file, for example: SF_200217_U2OS_TiO2_HCD_OT_rep1.full.mzml.instanovo-1.2.2.transformer.model-instanovo-v1.2.0.denovo.greedy.beams-1.normalized-columns.csv
  3. Select the corresponding spectrum file SF_200217_U2OS_TiO2_HCD_OT_rep1.mzML
  4. Load the results.

Observed Behavior

PDV shows an empty error dialog

Screenshot From 2026-06-19 09-50-55

and logs repeated table rendering exceptions like:

java.lang.NumberFormatException: For input string: "8,6407"
      at java.lang.Double.valueOf(Double.java:755)
      at PDVGUI.gui.utils.TableModel.DatabaseTableModel.getValueAt(DatabaseTableModel.java:344)
      at PDVGUI.gui.utils.TableModel.DatabaseTableModel.getColumnClass(DatabaseTableModel.java:480)

Expected Behavior

PDV should load and render result tables correctly regardless of the user’s JVM/system locale.

Fix

This PR adds a shared DecimalFormats helper that creates DecimalFormat instances with locale-independent decimal symbols using Locale.US.

It updates the affected GUI table models, importers, exporters, spectrum display, and CLI formatting code to use this helper. It also updates remaining numeric String.format(...) calls to pass Locale.US explicitly.

Validation

  • Verified under Locale.GERMANY that:
    • default DecimalFormat("#.0000") produces 8,6407
    • the new helper produces 8.6407
    • Double.valueOf("8.6407") succeeds

@wenbostar
wenbostar requested a review from KaiLiCn June 19, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant