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

Tom Hawtin Thomas.Hawtin at Sun.COM
Sun Mar 23 12:53:46 EDT 2008

Bill Pugh wrote:
> M M WL: Sychronization on getClass rather than class literal in 
> sun.applet.AppletPanel$9.run()  At AppletPanel.java:[line 1041]

Fortunately this one is in an anonymous inner class and also in a sun.* 
package (not a public API and not accessible from untrusted code). But 
as an anonymous inner class it seems to be an odd thing to want to do 
(although you can't use the .class notation in such a context). Looking 
at the code it seems to be locking the wrong object. It should be doing 
AppletPanel.this.getClass() (or rather AppletPanel.class or, if it were 
made final, classloaders). Getting the wrong this in an anonymous inner 
class isn't uncommon either, particularly when any Object will do.

Tom Hawtin

More information about the Concurrency-interest mailing list