summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/NonThreadSafeLazyInitializationInspection.java
blob: 20d62f94cb4e78e46208c4eb2396b53a391a17e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.siyeh.igtest.threading;

public class NonThreadSafeLazyInitializationInspection {
    private static Object foo;

    static
    {
        if (foo == null) {
            foo = new Object();
        }

    }

    {
        if (foo == null) {
            foo = new Object();
        }

    }

    public void instMethod() {
        if (foo == null) {
            foo = new Object();
        }
    }

    public void lockedInstMethod() {
        synchronized (NonThreadSafeLazyInitializationInspection.class) {
            if (foo == null) {
                foo = new Object();
            }
        }
    }
}