Compare integers without overflowing subtraction

Proprietary

Replace a single-return Comparable.compareTo or Comparator.compare implementation that subtracts two primitive ints with Long.signum((long) left - right). Widening before subtraction preserves the sign without overflow and avoids requiring newer runtime comparison APIs. Int subtraction can reverse the required ordering. Only the comparison contract determines this edit: ordinary arithmetic, overloads that do not implement the contract, smaller integral types, floating point, casts, compound arithmetic, lambdas and multi-statement methods are left alone. Known nonnegative length/size/ordinal differences and subtraction of zero are skipped because they cannot overflow. Likely test sources, Java package-name conflicts and unproven imported/inherited names are left alone. Requires a known Java 7+ source level.

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

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