Skip to content

Fix BEAUti crash for single valued distr inputs (ScalarDistributionInputEditor) - #126

Merged
walterxie merged 1 commit into
masterfrom
fix/scalar-distribution-editor-single-distr-input
Jul 27, 2026
Merged

Fix BEAUti crash for single valued distr inputs (ScalarDistributionInputEditor)#126
walterxie merged 1 commit into
masterfrom
fix/scalar-distribution-editor-single-distr-input

Conversation

@alexeid

@alexeid alexeid commented Jul 27, 2026

Copy link
Copy Markdown
Member

Problem

Opening the Priors panel in BEAUti with a package that wraps a distribution in another Distribution — e.g. bModelTest's BMTPrior, which has a single ScalarDistribution valued distr input — pops up "Could not add entry for distr" (BEAST2-Dev/bModelTest#10):

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
	at beastfx.app.inputeditor.ScalarDistributionInputEditor.createComboBox(ScalarDistributionInputEditor.java:627)
	at beastfx.app.inputeditor.ScalarDistributionInputEditor.init(ScalarDistributionInputEditor.java:119)
	at beastfx.app.inputeditor.InputEditorFactory.createInputEditor(InputEditorFactory.java:264)
	at beastfx.app.inputeditor.InputEditorFactory.createInputEditor(InputEditorFactory.java:145)

init() assumed the input is always a list of distributions with a valid item number:

List<?> list = (List<?>) input.get();
PartitionContext context = doc.getContextFor((BEASTInterface) list.get(itemNr));

For a single valued distr input this is reached with the distribution itself as value and itemNr == -1, so it throws. scalarTemplates had already been assigned at that point while templateDomains was still empty, so every editor created afterwards skipped the scalarTemplates == null guard and died on templateDomains.get(k++) — the reported symptom. The combo box change handler already had a branch for non-list inputs, so single valued inputs were clearly meant to be supported.

Fix

  • resolve the distribution being edited from either the list entry or the value of the input itself (getDistribution)
  • publish the template caches only once they are complete, so a failure can no longer leave them inconsistent
  • fall back to the partition context of the object owning the input when the nested distribution has no ID of its own (contextFor)
  • register a replacement distribution as output of the object owning the input rather than of the distribution it replaces
  • suppress the combo box, rather than throw, when no templates are known, and null check it before adding it to the pane

Test

ScalarDistributionInputEditorTest builds a BeautiDoc from the Standard template and asks InputEditorFactory for an editor for the distr input of a Distribution wrapper twice, which is what BEAUti does when rendering a panel. Without the fix it reproduces both the initial ClassCastException and the IndexOutOfBoundsException from the issue; with the fix it passes.

Full beast-fx suite: 23 run, 0 failures, 0 errors (11 skipped).

The editor assumed its input is always a list of distributions, so it
failed when created for a single ScalarDistribution valued input, such as
the distr input of a Prior. Since the static template caches were only
half filled when that failed, every editor created afterwards failed as
well with an unrelated IndexOutOfBoundsException, which is what BEAUti
reported to the user (see BEAST2-Dev/bModelTest#10).

- resolve the distribution being edited from either the list entry or the
  value of the input itself
- publish the template caches only once they are complete
- fall back to the partition context of the object owning the input when
  the nested distribution has no ID of its own
- register a replacement distribution as output of the object owning the
  input rather than of the distribution it replaces
- suppress the combo box, rather than throw, when no templates are known
@walterxie
walterxie merged commit a9d9eca into master Jul 27, 2026
1 check passed
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.

2 participants