Question

I have the following Java code:

public class Something {

    static {
        new Something();
    } 

    public static final int[] EMPTY_INT_ARRAY = new int[0];
}

I'm using FindBugs to look for code errors, but the following error is never raised:

SI: Static initializer creates instance before all static final fields assigned (SI_INSTANCE_BEFORE_FINALS_ASSIGNED)

The class's static initializer creates an instance of the class before all of the static final fields are assigned.

Is this the correct case that should demonstrate this issue? why is it not picking up this code issue?

Was it helpful?

Solution

Not tried, but I think an example would be:

public class Something {

    static {
        new Something();
    }

    public static final int CONST = 42;
}

As lysergic-acid has found out, this error has a lower severity in FindBugs (16). You have to manually lower the min threshold to make it show.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top