【发布时间】:2014-01-06 00:02:05
【问题描述】:
在我的代码中针对以下几行运行 checkstyle 时出现此错误:
@Override
public String[] getDescriptions() {
return DESCRIPTIONS;
}
但说明 IS NOT 可变。定义为:
private static final String[] DESCRIPTIONS = new String[NUM_COLUMNS];
static {
// In a loop assign values to the array.
for (int i = 0; i < NUM_COLUMNS; ++i) {
DESCRIPTIONS[i] = "Some value";
}
}
这是完整的错误信息:
"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."
相关问题:Link
【问题讨论】:
-
DESCRIPTIONS中的项目是可变的。
标签: java checkstyle mutable internals