vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
604 stars 166 forks source link

Make DataProvider.fetch return Stream<? extend T> #7029

Open mvysny opened 4 years ago

mvysny commented 4 years ago

Loosely connected to #6617 but the use-case for this is different.

My use-case is that I have a TreeGrid<Item> with various types of items: an ItemGroup represents inner nodes, while an ItemLeaf represents leaves, and both of them implement the Item interface.

I have an API which returns List<ItemLeaf> (List<ItemLeaf> findLeavesForGroup(long groupId)) which I would like to simply return from AbstractBackEndHierarchicalDataProvider.fetchChildrenFromBackEnd(), but I can't:

If fetchChildrenFromBackEnd() would return Stream<? extends Item> then returning Stream<ItemLeaf> would be possible.

Vaadin 14.0.12

jhult commented 4 years ago

@mvysny, it seems that this is not a recommended pattern. See here for more details.

Can you provide a code sample (or link to one) for how exactly you are using the fetchChildrenFromBackEnd method? There might be a better solution.

mvysny commented 4 years ago

@jhult I think that particular FindBugs rule does not apply here: the rule discusses List and makes the point by trying to insert a Cat into the List. In this case we have a Stream which is a read-only API with no mutation parameters.

Can you provide a code sample (or link to one) for how exactly you are using the fetchChildrenFromBackEnd method? There might be a better solution.

It's the other way around: the Grid is calling fetchChildrenFromBackEnd() to populate itself; I'm merely trying to implement a HierarchicalDataProvider which on root level is trying to return List<ItemGroup> and on a non-root level it's trying to return List<ItemLeaf>.

Maybe I should provide a more concrete example, but I can't - it's customer's code and I can't make it public. I could make similar case by showing a simple file-system and having List<Directory> and List<File>, but I hoped that the issue description would be enough...

pleku commented 4 years ago

At least the changes proposed in #7653 would be breaking changes and the added value is too small compared to the potential harm it would cause.

I think the added value is more significant for TreeGrid and thus it could be perhaps done only for AbstractHierarchicalDataProvider which probably doesn't have that many implementations, but there potentially breaking some applications could be more adjust.