spotbug检查提示
Random object created and used only once
代码:
for (int i = 0; i < 1; i++) {
sb.append(numberArr[r.nextInt(numberArr.length)]);
}
?Random object created and used only once This code creates a java.util.Random object, uses it to generate one random number, and then discards the Random object. This produces mediocre quality random numbers and is inefficient. If possible, rewrite the code so that the Random object is created once and saved, and each time a new random number is required invoke a method on the existing Random object to obtain it. If it is important that the generated Random numbers not be guessable, you must not create a new Random for each random number; the values are too easily guessable. You should strongly consider using a java.security.SecureRandom instead (and avoid allocating a new SecureRandom for each random number needed).
itemsViewJson(, int, int, int) may expose internal representation by returning ontroller.paginationResult
May expose internal representation by returning reference to mutable object Returning a reference to a mutable object value stored in one of the object's fields exposes the internal representation of the object.??If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Returning a new copy of the object is better approach in many situations.
返回对存储在对象某个字段中的可变对象值的引用会暴露对象的内部表示。如果实例被不受信任的代码访问,并且对可变对象未经检查的更改会损害安全性或其他重要属性,那么您需要做一些不同的事情。在许多情况下,返回对象的新副本是更好的方法。?
Field is a mutable array
如:
protected static final String [] COLUMN_NAMES = new String[]{"date","customerNumber","customerName",
"account","emailAdress","mobilePhoneNumber","emailStatus"};
检查会提示数组不是能修改
处理方法:
private static final String [] COLUMN_NAMES = new String[]{"date","customerNumber","customerName",
"account","emailAdress","mobilePhoneNumber","emailStatus"};
protected static List<String> getColumnNames() {
return Collections.unmodifiableList(Arrays.asList(COLUMN_NAMES));
}
将数组转为私有的?再使用Collections.unmodifiableList?不修改数组的方法返回
引用 :java - Mutable fields should not be "public static" - Stack Overflow
|