Find back references to capturing groups that cannot have matched

Proprietary

Marks a regular expression literal passed to Pattern.compile, Pattern.matches, String.matches, String.split, String.replaceAll or String.replaceFirst that holds a back reference, such as \1 or \k<name>, which can never match because no path through the pattern closes its capturing group before the reference is reached: the group number does not exist, the group is declared after the reference or encloses it, or the group sits in another alternative. Java makes such a reference fail instead of matching the empty string. A reference is left alone when its group can match inside a repeated or possessive group, a lookaround or an atomic group, since Java can keep that capture from an earlier iteration or a failed attempt. Patterns that are not a single string literal, patterns that do not compile (such as \k<name> in front of the group it names), patterns in comments mode, patterns where a {n} count directly follows another quantifier, and Pattern.compile calls with a flags argument other than a literal 0 are not inspected. Test sources are not searched.

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

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