tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 49778] New: Inconsistent synchronization in SimplePool.java
Date Thu, 19 Aug 2010 08:59:46 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=49778

           Summary: Inconsistent synchronization in SimplePool.java
           Product: Tomcat 6
           Version: 6.0.18
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: fslzdd@gmail.com


In class org.apache.tomcat.util.collections.SimplePool, current is a mutable
field. In method put/get, current field is updated with a lock held. But in
method getCount(), the access to current field is not protected by a lock. 

In current Java memory model, the up-to-date current field value is not
guaranteed to be seen in the absence of synchronization. So getCount() method
can return a stale or inconsistent value, which results in undesired behavior.

Proposed solution:

public int getCount() {
  int ret = 0;
  synchronized (lock) {
    ret = current+1;
  }
  return ret;
}

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

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


Mime
View raw message