[concurrency-interest] New bug pattern, way to common

Jason Mehrens jason_mehrens at hotmail.com
Fri Mar 21 14:01:03 EDT 2008


Another broken pattern that findbugs (1.1.3) doesn't catch is using getClass() and synchronized.  Since getClass() doesn't always return the Class object that defines the static field (because of a sub class) it is a case of synchronized on different objects.  This may not be common but it is broken.
 
The following is an example, the original was from "yet another broken double checked locking attempt":
 
public class NonFinalClassShouldUseClassLiteral {  private static int count;
  public NonFinalClassShouldUseClassLiteral() {    synchronized (getClass()) {      count++;    }  }}
 
Jason
_________________________________________________________________
Test your Star IQ
http://club.live.com/red_carpet_reveal.aspx?icid=redcarpet_HMTAGMAR
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080321/0ba748b4/attachment.html 


More information about the Concurrency-interest mailing list