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
findAny()
filter()
The best way to avoid NPE is:
Optional encryption = sseEncryptionList.stream() .filter(Objects::nonNull) .filter(n -> "AES256".equals(n.textValue())) .findAny();
"AES256".equals(n.textValue())) will not throw NPE if n.textValue() is null
"AES256".equals(n.textValue()))