简体   繁体   English

FindBugs和静态初始化顺序

[英]FindBugs and static initialization order

I have the following Java code: 我有以下Java代码:

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: 我正在使用FindBugs来查找代码错误,但从未引发以下错误:

SI: Static initializer creates instance before all static final fields assigned (SI_INSTANCE_BEFORE_FINALS_ASSIGNED) SI:静态初始化程序在分配所有静态最终字段之前创建实例(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). 由于麦角酸已经发现,这个错误在FindBugs中的严重程度较低(16)。 You have to manually lower the min threshold to make it show. 您必须手动降低最小阈值才能显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM