Class DoubleCheckedLockingRule

  • All Implemented Interfaces:
    AstVisitor<Object,​Object>, JavaParserVisitor, JavaVisitor<Object,​Object>, PropertySource, 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 (dnoyeb@users.sourceforge.net)