Skip to content

Commit 00bd64a

Browse files
tomivirkkiclaude
andauthored
fix: avoid NPE in ChartRenderer when chart type is null (#9111)
## Summary - Fixes NPE in `ChartRenderer.applyAxisDefaults` when chart type is not set (data-only update without configuration). `Set.of().contains(null)` throws NPE; added null guard to treat unset type as default (line chart with category axis). - Found during a DX test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3edbbba commit 00bd64a

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

vaadin-ai-components-flow-parent/vaadin-ai-components-flow/src/main/java/com/vaadin/flow/component/ai/chart/ChartRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private static void applyAxisDefaults(Configuration config,
170170
// Collects from all series to handle multi-series with different
171171
// categories (e.g. stacked by region where each region has
172172
// different months).
173-
if (!NO_CATEGORY_AXIS_TYPES.contains(chartType)) {
173+
if (chartType == null || !NO_CATEGORY_AXIS_TYPES.contains(chartType)) {
174174
var categories = extractCategories(allItems);
175175
if (!categories.isEmpty()) {
176176
xAxis.setCategories(categories.toArray(new String[0]));

vaadin-ai-components-flow-parent/vaadin-ai-components-flow/src/test/java/com/vaadin/flow/component/ai/chart/ChartRenderingTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,23 @@ void smallXValuesDoesNotSetDatetimeAxisType() {
482482
chart.getConfiguration().getxAxis().getType());
483483
}
484484

485+
@Test
486+
void nullChartTypeSetsCategoriesFromNames() {
487+
databaseProvider.results = List.of(
488+
row("category", "Jan", "value", 100),
489+
row("category", "Feb", "value", 200));
490+
491+
updateData("SELECT category, value FROM t");
492+
controller.onRequestCompleted();
493+
494+
String[] categories = chart.getConfiguration().getxAxis()
495+
.getCategories();
496+
Assertions.assertNotNull(categories,
497+
"Categories should be set when chart type is null");
498+
Assertions.assertArrayEquals(new String[] { "Jan", "Feb" },
499+
categories);
500+
}
501+
485502
@Test
486503
void mixedXValuesSmallAndLargeDoesNotSetDatetime() {
487504
// First value is a timestamp, second is small — should NOT be

0 commit comments

Comments
 (0)