I am having trouble figuring why findAny()
throws a null pointer exception after filter()
operation on a stream. In this particular test case, the filt
Your confusion comes from the fact that you filter
first - and you would expect the filter
method to be somewhere in the stack trace; but notice that intermediate operations do nothing per-se, they are executed lazily and only kick in when a terminal operation is present (such as findAny
in your case). It's actually there in the stack trace (the filter method
), but it looks like this: Example.Main.lambda$main$0(Main.java:41)
.
If you want to filter null values, first do:
.filter(Objects::nonNull)
.filter(n -> n.textValue().equals("AES256"))
.findAny()