#1471 [java] DoubleCheckedLocking: False positives

PMD-5.3.7
closed
java (55)
PMD
3-Major
Bug
5.3.x
DoubleCheckedLocking
2016-06-25
2016-04-19
Alix Warnke
No

The rule triggers on the following implementation (in a Java7 codebase):

private static volatile Foo instance;

public static Foo getInstance() {
    Foo result = instance;
    if (result == null) {
        synchronized (Foo.class) {
            result = instance;
            if (result == null) {
                result = instance = new Foo();
            }
        }
    }
    return result;
}

This implementation should be OK for JDK 5+ according to: http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html (section "Under the new Java Memory Model")

Discussion

  • Andreas Dangel

    Andreas Dangel - 2016-04-23
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.7
    • Affects version: 5.4.0 --> 5.3.x
     
  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • labels: --> java
    • summary: False positives for DoubleCheckedLocking --> [java] DoubleCheckedLocking: False positives
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks