Class DoubleCheckedLockingRule

  • All Implemented Interfaces:
    JavaParserVisitor, net.sourceforge.pmd.lang.rule.ImmutableLanguage, net.sourceforge.pmd.properties.PropertySource, net.sourceforge.pmd.Rule

    public class DoubleCheckedLockingRule
    extends AbstractJavaRule
     void method() {
       if (x == null) {
         synchronized(this){
           if (x == null) {
             x = new | method();
           }
         }
       }
     }
     

    The error is when one uses the value assigned within a synchronized section, outside of a synchronized section.

     if (x == null) // is outside of synchronized section
       x = new | method();
     

    Very very specific check for double checked locking.

    Author:
    CL Gilbert ([email protected])