File: InvalidPatternSyntax.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (10 lines) | stat: -rw-r--r-- 531 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
This error is triggered by calls to regex-accepting methods with invalid string
literals. These calls would cause a PatternSyntaxException at runtime.

We deliberately do not check `java.util.regex.Pattern#compile` as many of its
users are deliberately testing the regex compiler or using a vacuously true
regex.

`"."` is also discouraged, as it is a valid regex but is easy to mistake for
`"\\."`. Instead of e.g. `str.replaceAll(".", "x")`, prefer `Strings.repeat("x",
str.length())` or `CharMatcher.ANY.replaceFrom(str, "x")`.