summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2019-02-22 15:11:39 +0200
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2019-03-06 10:30:35 +0200
commite5d206f7980179c68e80f1316ec0005d9717380c (patch)
tree1ece96400dc3932ba212c7b3880cc491915f197f
parent52e8a4212bc1b3639636df7909ed8fda039a12da (diff)
downloadvaadin-framework-e5d206f7980179c68e80f1316ec0005d9717380c.tar.gz
vaadin-framework-e5d206f7980179c68e80f1316ec0005d9717380c.zip
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
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java11
1 files changed, 10 insertions, 1 deletions
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<T> extends AbstractSingleSelect<T>
// 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.