Class DoubleCheckedLockingRule

  • All Implemented Interfaces:
    net.sourceforge.pmd.lang.ast.AstVisitor, JavaVisitor, net.sourceforge.pmd.lang.rule.Rule, net.sourceforge.pmd.properties.PropertySource

    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 (dnoyeb@users.sourceforge.net)
    • Constructor Detail

      • DoubleCheckedLockingRule

        public DoubleCheckedLockingRule()
    • Method Detail

      • buildTargetSelector

        protected @NonNull net.sourceforge.pmd.lang.rule.RuleTargetSelector buildTargetSelector()
        Overrides:
        buildTargetSelector in class net.sourceforge.pmd.lang.rule.AbstractRule