xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 44178] New: - Race condition in CleanerThread.java getReferenceQueue() method
Date Mon, 07 Jan 2008 17:33:12 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=44178>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=44178

           Summary: Race condition in CleanerThread.java getReferenceQueue()
                    method
           Product: Batik
           Version: 2.0
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Utilities
        AssignedTo: batik-dev@xmlgraphics.apache.org
        ReportedBy: archie@dellroad.org


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).

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org


Mime
View raw message