Go for a functional style to express the result:
.filter(foo -> foo.getName() != null && foo.getName().contains(filterName))
:
.filter(foo -> foo.getName() != null)
.filter(foo -> foo.getName().contains(filterName))
Foo:: getName (Objects:: isNull) , .
filterName , Strings.isEmptyOrNull .