Browse Source

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
tags/8.8.0.beta1
Tatu Lund 5 years ago
parent
commit
19f839154e
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      server/src/main/java/com/vaadin/ui/ComboBox.java

+ 10
- 1
server/src/main/java/com/vaadin/ui/ComboBox.java View File

@@ -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.

Loading…
Cancel
Save