Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-802

[PATCH] Race condition in CleanerThread.java getReferenceQueue() method

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 1.8
    • Fix Version/s: None
    • Component/s: Utilities
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: All

      Description

      In org.apache.batik.util.CleanerThread we see:

      public static ReferenceQueue getReferenceQueue() {
      if ( queue == null ) {
      synchronized (CleanerThread.class)

      { queue = new ReferenceQueue(); thread = new CleanerThread(); }

      }
      return queue;
      }

      This method is not thread safe due to a race condition. The test for "if (queue
      == null)" needs to be inside the synchronized block, not outside of it. As
      written, it's possible for the initialization code to be executed more than once.

      Fix: make the entire method synchronized, or add an additional test for "if
      (queue == null)" within the synchronized block (but see
      http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html for why
      the variable needs to remain volatile).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              archie Archie Cobbs
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: