Skip to content

Files

Latest commit

 

History

History
27 lines (19 loc) · 714 Bytes

StaticMatcherField.md

File metadata and controls

27 lines (19 loc) · 714 Bytes

Pattern: Static Matcher field

Issue: -

Description

Matcher objects should not be used as static fields. Calendars are inherently unsafe for multi-threaded use. Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the application.

Example of violations:

// two violations
class SomeClass {
  static Matcher matcher1
  static java.util.regex.Matcher matcher2
}

// these usages are OK
class SomeCorrectClass {
  private Matcher matcher1
  static ThreadLocal<Matcher> matcher2
}

Further Reading