Find Map.computeIfAbsent and Map.computeIfPresent calls with a lambda returning null

Proprietary

Marks the method name of computeIfAbsent(..) and computeIfPresent(..) calls on a java.util.Map whose second argument is a lambda with the null literal as its body. Such a call never stores a null value: computeIfAbsent records no mapping and computeIfPresent removes the existing entry. No fix is offered, because replacing the call with containsKey and put(key, null) would store a mapping the current code never stores. Only receivers declared as Map itself, and unqualified calls to the methods Map declares, are searched, as a subtype such as TreeMap may specify these methods differently. Map.super calls, Map.compute(..), block-bodied lambdas, parenthesized or cast null bodies, method references and lambdas returning a variable are not marked. Test sources are not searched.

io.moderne.staticanalysis.FindNullFromMapCompute
mod run . --recipe=io.moderne.staticanalysis.FindNullFromMapCompute

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.