java:S2885 does not recognize static field initialized with DateFormat.getDateInstance()


Not sure whether this is a false-positive…
No issue is raised by S2885 in this case:

public static final DateFormat FORMAT = DateFormat.getDateInstance();
(static field is initialized with DateFormat.getDateInstance())

Is that correct? (are there perhaps too many false-positives possible in this case?)

  • SonarJava: 6.3 (build 21585)
  • SonarQube: Community Edition; Version 7.9.1 (build 27448)

Hi Holger,

Each call to DateFormat.getDateInstance() return a new SimpleDateFormat that should not be used in a multi-thread context. So yes, the rule S2885 should also report the above case. It’s called a false-negative and I have created the SONARJAVA-3400 ticket to improve the rule.

Thanks for your feedback,


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.