문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top