Menu

#1347 DC_DOUBLECHECK false-positive when loading superclass field

3.0.1
closed-fixed
None
5
2015-01-12
2015-01-12
No

Based on this discussion thread: DC_DOUBLECHECK cannot properly retrieve field volatile modifier if it's declared in the superclass. Here's the testcase:

public class Bug1347 {

    protected volatile List<Object> types;

    protected List<Object> types2;

    public static class B extends Bug1347 {
        @NoWarning("DC_DOUBLECHECK")
        List<Object> getTypes() {
            if (types == null) {
                synchronized (this) {
                    if (types == null) {
                        types = new ArrayList<>();
                    }
                }
            }
            return types;
        }

        @ExpectWarning("DC_DOUBLECHECK")
        List<Object> getTypes2() {
            if (types2 == null) {
                synchronized (this) {
                    if (types2 == null) {
                        types2 = new ArrayList<>();
                    }
                }
            }
            return types2;
        }
    }
}

Related

Discussion: DC_DOUBLECHECK question

Discussion

  • Tagir Valeev

    Tagir Valeev - 2015-01-12
    • status: open --> closed-fixed
    • Group: 3.x --> 3.0.1
     

Log in to post a comment.

MongoDB Logo MongoDB