public class ConfigInDB {
public static int testA = 123, testB = 3;
public static String testC = "";
}
findbug 里提示:
com.base.ConfigInDB.testC isn't final but should be
This static field public but not final, and could be changed by malicious code or by accident from another package. The field could be made final to avoid this vulnerability.
这是为啥?
------解决思路----------------------
你贴的这段代码 没问题阿
------解决思路----------------------
findbugs的提示: 因为是public,可能会被其他类改变值,建议final 限制
------解决思路----------------------
遇到过这种情况,findbugs 应该会查看该变量有没有在使用中被修改过,如果没有被修改过,那么它会建议使用final修饰的。
可以参考下 static 和 final修饰变量的初始化加载过程
Java - Static和Final修饰类属性变量及初始化
Java关键字final、static使用总结