From 19f839154e49c487ff9d156e962acb4df889a553 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Fri, 22 Feb 2019 15:11:39 +0200 Subject: Fixing NPE when ItemCaptionGenerator returns null (#11435) * Fixing NPE when ItemCaptionGenerator returns null Adding similar logic in setDataProvider(...) as used elsewhere in ComboBox.java (e.g. generateData(..) see line 314) fixes issue #11434 --- server/src/main/java/com/vaadin/ui/ComboBox.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index 0a5a36c856..a976782ecc 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -453,9 +453,18 @@ public class ComboBox extends AbstractSingleSelect // Must do getItemCaptionGenerator() for each operation since it might // not be the same as when this method was invoked setDataProvider(listDataProvider, filterText -> item -> captionFilter - .test(getItemCaptionGenerator().apply(item), filterText)); + .test(getItemCaptionOfItem(item), filterText)); } + // Helper method for the above to make lambda more readable + private String getItemCaptionOfItem(T item) { + String caption = getItemCaptionGenerator().apply(item); + if (caption == null) { + caption = ""; + } + return caption; + } + /** * Sets the data items of this listing and a simple string filter with which * the item string and the text the user has input are compared. -- cgit v1.2.3