Skip to content

Fix #799: empty-string custom tick labels crash TextLayout#968

Merged
timmolter merged 1 commit into
developfrom
timmolter/fix-799-empty-tick-label-crash
Jun 9, 2026
Merged

Fix #799: empty-string custom tick labels crash TextLayout#968
timmolter merged 1 commit into
developfrom
timmolter/fix-799-empty-tick-label-crash

Conversation

@timmolter

Copy link
Copy Markdown
Member

Problem

When a custom Y-axis (or X-axis) tick label formatter returns "" to suppress a label, AxisTickLabels.paint() passed the empty string directly to the TextLayout constructor, which throws IllegalArgumentException: Zero length string passed to TextLayout constructor.

Reproducer:

chart.setCustomYAxisTickLabelsFormatter(yValue -> {
    Double label = myMap.get(yValue);
    return label == null ? "" : label.toString(); // "" for unmapped values
});
BitmapEncoder.saveBitmap(chart, "output.png", BitmapEncoder.BitmapFormat.PNG); // crashes

Root Cause

AxisTickLabels.paint() checked tickLabel != null before passing labels to TextLayout, but did not check for empty strings. TextLayout accepts null but throws on "".

ColocatedSlaveLabels.paint() had the same gap (its sibling method maxSlaveWidth() already guarded for !isEmpty() correctly).

Fix

Treat "" the same as null — silently skip rendering. No label text is drawn; tick marks remain visible (consistent with the existing null/log-axis behaviour and the documented " " hide-label workaround from #792).

Files changed:

  • AxisTickLabels.java — add !tickLabel.isEmpty() to the Y-axis guard and both X-axis guards
  • ColocatedSlaveLabels.java — add !label.isEmpty() to paint() to match the existing guard in maxSlaveWidth()
  • XYChartTest.java — replace @Disabled stub with three @Test regressions: all-duplicate labels, Y-axis empty labels, X-axis empty labels
  • TestForIssue799.java — headless-safe demo class

Closes #799

When a custom Y- (or X-) axis tick formatter returns "" to suppress a
label, AxisTickLabels.paint() passed the empty string to the TextLayout
constructor, which throws IllegalArgumentException.

Fix: treat empty strings the same as null in all three label-guard
checks inside AxisTickLabels.paint(), and in the matching guard in
ColocatedSlaveLabels.paint() (which already handled this correctly in
maxSlaveWidth() but not in paint()).

Changes:
  both X-axis guards before TextLayout construction
  to match the existing guard in maxSlaveWidth()
- XYChartTest.java: replace the @disabled stub with three proper
  @test regressions covering all-duplicate labels, Y-axis empty labels,
  and X-axis empty labels
- TestForIssue799.java: add headless-safe demo class

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@timmolter timmolter merged commit e036430 into develop Jun 9, 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.

BitmapEncoder saveBitmap no response when XYChart setyAxisTickLabelsFormattingFunction is called before.

1 participant