Skip to content

Commit dfa4a12

Browse files
fix: add null check in setFooterToolbar (#132)
* fix: add null check in setFooterToolbar Close #131 --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 3d73abc commit dfa4a12

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/FooterToolbarGridHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.vaadin.flow.component.grid.FooterRow.FooterCell;
2525
import com.vaadin.flow.component.grid.Grid;
2626
import java.io.Serializable;
27+
import java.util.Objects;
2728
import lombok.RequiredArgsConstructor;
2829

2930
@SuppressWarnings("serial")
@@ -35,6 +36,7 @@ class FooterToolbarGridHelper implements Serializable {
3536
private FooterCell footerCell;
3637

3738
public void setFooterToolbar(Component toolBar) {
39+
Objects.requireNonNull(toolBar, "Toolbar component must not be null");
3840
Grid<?> grid = helper.getGrid();
3941
if (grid.getColumns().isEmpty()) {
4042
throw new IllegalStateException("Cannot set footer toolbar: Grid columns have not been configured.");

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/FooterToolbarTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.gridhelpers.test;
2121

22+
import com.flowingcode.vaadin.addons.gridhelpers.GridHelper;
2223
import com.flowingcode.vaadin.addons.gridhelpers.GridHelper;
2324
import com.vaadin.flow.component.grid.Grid;
2425
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
26+
import org.junit.Assert;
2527
import org.junit.Test;
2628

2729
public class FooterToolbarTest {
@@ -42,4 +44,16 @@ public void testSetFooterToolbarBeforeColumnsConfiguredThrowsException() {
4244
var toolbarFooter = new HorizontalLayout();
4345
GridHelper.addToolbarFooter(grid, toolbarFooter);
4446
}
47+
48+
@Test(expected = NullPointerException.class)
49+
public void testSetFooterToolbarWithNullToolbarThrowsException() {
50+
Grid<Bean> grid = new Grid<>(Bean.class, false);
51+
grid.addColumn(x -> x).setHeader("Header");
52+
try {
53+
GridHelper.addToolbarFooter(grid, null);
54+
} catch (NullPointerException e) {
55+
Assert.assertEquals("Toolbar component must not be null", e.getMessage());
56+
throw e;
57+
}
58+
}
4559
}

0 commit comments

Comments
 (0)