void (String s) { Optional<List<String>> strings = Optional.ofNullable(s) .map(OptionalStreamInlining::getLetters); Optional<String> s1 = strings .stream() .flatMap(Collection::stream) .min(Comparator.naturalOrder()); if (s1.isPresent()) { System.out.println(s.length()); } else { System.out.println(); System.out.println(s.<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>()); } }