Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

list.stream().collect(Collectors.toList()); returns empty list

choices is a List of two elements

but choices.stream().collect(Collectors.toList()); returns an empty list

Would anyone know why?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

//returns poll with list of choices
public Poll accessPoll(String pollId) {
        return pollRepository.findById(pollId).orElseThrow(
                () -> new IllegalStateException(String.format("No poll found for the ID: %s.", upperCasePollId)));
}
List<Choice> choices = pollManager.accessPoll(pollId).getChoices(); //returns list of choices
List<Choice> choices1 = pollManager.accessPoll(pollId).getChoices()
                .stream().collect(Collectors.toList()); //returns empty list

enter image description here

enter image description here

>Solution :

Look carefully at your screenshots. Your method getChoices() returns not a regular list but IndirectList which extends not a regular Collection but a Vector and that is why streams don’t work as expected. This is a known bug in EclipseLink,
you can read about it more here and here.

To overcome this behaviour, you can try to update your EclipseLink version up to 2.6.0, or you may try to wrap it with a new collection, like new ArrayList<>()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading