A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4483 below:

[java] NonThreadSafeSingleton false positive with double-checked locking · Issue #4483 · pmd/pmd · GitHub

Affects PMD Version: 6.x

Rule: NonThreadSafeSingleton

Description:

The rule reports a violation even for double checked locking, that is implemented correctly.

Code Sample demonstrating the issue:

public class Foo {
    private static volatile Object o;
    public static Object getO() {
        if (o == null) {   // violation
            synchronized(Foo.class) {
                if (o == null) {
                    o = new Object();
                }
            }
        }
        return o;
    }
}

Expected outcome: No violation

Note: This has already been fixed for PMD 7.0.0-rc1 via #3474. This issue is just there for documentation.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4