Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-367

ntp.TimeStamp uses incorrect lazy initialisation of static fields simpleFormatter and utcFormatter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0
    • Component/s: None
    • Labels:
      None

      Description

      Findbugs reports that ntp.TimeStamp uses incorrect lazy initialisation of the static fields simpleFormatter and utcFormatter.
      This is because the static fields are written and read without synchronisation. One proposed solution is to make the static fields volatile.

      The fields are SoftReferences containing SimpleDateFormat instances. SimpleDateFormat (SDF) is not thread-safe, so when it is used, the code has to synchronize on the instance.

      Are the SoftReferences necessary? Does it really matter if the field cannot be garbage-collected?
      If not, an Init on Demand Holder (IODH) be safer, and would avoid creating the instance if it was not needed.

      Also, is it necessary to use static fields to hold the SimpleDateFormat instances, given that this requires the synchronisation when using the methods toUTCString/toDateString?

      The other mutable classes in the package are not thread-safe (mutable fields are not volatile or synch) so overall thread-safety for the package would not be compromised by using instance fields and removing the SDF synchronisation and SoftReference.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sebb@apache.org Sebb
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: