Replace a reversed copy with a reversed view

Proprietary

Removes Collections.reverse(list) on a local list that is read once afterwards, and reads it through its reversed() view instead, which reverses nothing in place, on Java 21 or later. The list must be created in the method, with a list constructor other than CopyOnWriteArrayList or with null, and only filled before it is reversed; afterwards it must be read exactly once, by iterating it, querying it with a method such as get, size or stream, or copying it. It is left alone when that read is outside the block holding the call or reads the list's class, monitor or clone(), when a lambda, class, iterator or stream made before the call reads the list, when the call is in a loop, lambda, try or similar statement that does not also hold the list's declaration, and in test sources.

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

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