I'm trying to understand the full implication of the intellij synchronization on non-final fields warning, which has this description:
This inspection reports instances of synchronized statements where the lock expression is a non-final field. Such statements are unlikely to have useful semantics, as different threads may be locking on different objects even when operating on the same object. An example usage is the following where a multiple operations on the domainCache variable is done in a synchronized block so that the remove/insert are atomic: public class JaasSecurityManager { private CachePolicy domainCache; private Subject updateCache(Principal principal) { synchronized( domainCache ) { if( domainCache.peek(principal) != null ) domainCache.remove(principal); domainCache.insert(principal, info); } } } In going over the current memory model docs: http://www.cs.umd.edu/~pugh/java/memoryModel/ http://gee.cs.oswego.edu/dl/jmm/cookbook.html http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf The only context I can see where this warning applies is if the domainCache variable is being changed. In that case two threads may actually be synchronizing/working on different objects, but that is fine in this case as the atomic block of ops only applies to the domainCache object. If other state was being referenced I can see a problem, but not for the illustrated usage. Am I missing something here? xxxxxxxxxxxxxxxxxxxxxxxxxxxx Scott Stark VP Architecture & Technology JBoss Inc. xxxxxxxxxxxxxxxxxxxxxxxxxxxx ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642 _______________________________________________ JBoss-Development mailing list JBoss-Development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-development