diff options
author | Tatu Lund <tatu@vaadin.com> | 2019-02-22 15:11:39 +0200 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2019-02-22 15:11:39 +0200 |
commit | 19f839154e49c487ff9d156e962acb4df889a553 (patch) | |
tree | 0ea700c6bf02c7bc37c0f529bf4a29bc5f03ebb9 | |
parent | 9d5bdaf89bd173bec7364d591377ca17bb5bb91d (diff) | |
download | vaadin-framework-19f839154e49c487ff9d156e962acb4df889a553.tar.gz vaadin-framework-19f839154e49c487ff9d156e962acb4df889a553.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.java | 11 |
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. |