Inspectopedia Help

Non-thread-safe 'static' field access

Reports access to static fields that are of a non-thread-safe type.

When a static field is accessed from an instance method or a non-synchronized block, multiple threads can access that field. This can lead to unspecified side effects, like exceptions and incorrect results.

Example:

class Sample { private static final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String method() { return df.format(""); } }

You can specify which types should be considered not thread-safe. Only fields with these exact types or initialized with these exact types are reported, because there may exist thread-safe subclasses of these types.

Inspection options

Option

Type

Default

Non-thread-safe classes

StringList

[java.text.Format, java.text.DateFormat, java.text.SimpleDateFormat, java.text.MessageFormat, java.text.DecimalFormat, java.text.ChoiceFormat, java.util.Calendar]

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023