Fix #799: empty-string custom tick labels crash TextLayout#968
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theTextLayoutconstructor, which throwsIllegalArgumentException: Zero length string passed to TextLayout constructor.Reproducer:
Root Cause
AxisTickLabels.paint()checkedtickLabel != nullbefore passing labels toTextLayout, but did not check for empty strings.TextLayoutacceptsnullbut throws on"".ColocatedSlaveLabels.paint()had the same gap (its sibling methodmaxSlaveWidth()already guarded for!isEmpty()correctly).Fix
Treat
""the same asnull— silently skip rendering. No label text is drawn; tick marks remain visible (consistent with the existingnull/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 guardsColocatedSlaveLabels.java— add!label.isEmpty()topaint()to match the existing guard inmaxSlaveWidth()XYChartTest.java— replace@Disabledstub with three@Testregressions: all-duplicate labels, Y-axis empty labels, X-axis empty labelsTestForIssue799.java— headless-safe demo classCloses #799