/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ package codetoanalyze.java.infer; import java.util.Collections; import java.util.List; import java.util.function.Function; public class InvokeDynamic { void invokeDynamicThenNpeBad(List list) { Object o = null; Collections.sort( list, (String a, String b) -> { return b.compareTo(a); }); o.toString(); } void npeInLambdaBad(List list) { Collections.sort( list, (String a, String b) -> { Object o = null; o.toString(); return b.compareTo(a); }); } // we still don't get this one (even with Javalib lambda rewriting) // because Collections.sort is skipped void FN_npeViaCaptureBad(List list) { String s = null; Collections.sort( list, (String a, String b) -> { return s.compareTo(a); }); } Integer npeViaSimpleCapture() { String s = null; Function f = (s1) -> s.length(); return f.apply(null); } Integer npeViaSimpleParamPassing() { Function f = (s) -> s.length(); return f.apply(null); } }