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

Bill Pugh pugh at cs.umd.edu
Sat Mar 22 10:57:30 EDT 2008


No, because using the synchronized modifier on a static method  
synchronizes
on the Class object.

While this does allow for malicious code to perform denial of service  
attacks,
the Java platform is pretty wide open to that.



	Bill


On Mar 22, 2008, at 9:15 AM, Rémi Forax wrote:

> Jason Mehrens a écrit :
>> 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.
> This case is cover by a more general rule: don't synchronized on
> internable object
> like Class, String, wrappers (Integer, etc.).
>>
>> 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
> Rémi
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest




More information about the Concurrency-interest mailing list