FindBugs解决方案。
参考
正文
EI: 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.
- 解决方案
EI2: May expose internal representation by incorporating reference to mutable object
- 官方描述
This code stores a reference to an externally mutable object into 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. Storing a copy of the object is better approach in many situations.
- 解决方案
Field is a mutable collection
- 官方描述
A mutable collection instance is assigned to a final static field, thus can be changed by malicious code or by accident from another package. Consider wrapping this field into Collections.unmodifiableSet/List/Map/etc. to avoid this vulnerability.
- 解决方案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
...
public static final Map<String, Object> ENGIN_DATATYPE;
static {
Map<String, Object> aMap = new HashMap();
aMap.put("Number", "NUMBER,FLOAT,DOUBLE,DECIMAL,BINARY_FLOAT,BINARY_DOUBLE");
aMap.put("String", "STRING,VARCHAR,CHAR,NCHAR,VARCHAR2,NVARCHAR2");
aMap.put("Date", "DATE");
aMap.put("Boolean", "BOOLEAN");
aMap.put("Integer", "INTEGER,TINYINT,SMALLINT,MEDIUMINT,INT");
aMap.put("BigNumber", "BIGNUMBER,BIGINT");
aMap.put("Binary", "BINARY");
aMap.put("Timestamp", "TIMESTAMP,DATETIME");
aMap.put("Internet Address", "INTERNET ADDRESS");
ENGIN_DATATYPE = Collections.unmodifiableMap(aMap);
}
近期评论