System.arraycopy--findbugs检查引发的更改

简介: EI2: This code stores a reference to an externally mutable object into the internal representation of the object.

EI2: 
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.

import java.io.Serializable;

public class TableModel implements Serializable {
    private static final long serialVersionUID = 6121579860453189567L;
    private String[][] data;
    private String[] columnNames;

    public TableModel(String[][] data, String[] columnNames) {
        this.data = new String[data.length][];
        System.arraycopy(data, 0, this.data, 0, data.length);
        this.columnNames = new String[columnNames.length];
        System.arraycopy(columnNames, 0, this.columnNames, 0, columnNames.length);
    }

    public void travel() {
        System.out.println(this.data == null);
        System.out.println(this.columnNames == null);
    }

    public static void main(String[] args) {
        String[][] data = {{"A1", "B1"}, {"A2", "B2"}, {"A3", "B3"}, {"A4", "B4"},};
        String[] columnNames = {"COL1", "COL2"};
        TableModel tableModel = new TableModel(data, columnNames);
        tableModel.travel();
    }

}

 

相关文章
|
2月前
报错:Keil5执行文件之后显示Target not created
报错:Keil5执行文件之后显示Target not created
230 0
|
4月前
|
SQL JSON Java
Java【问题记录 02】对象封装+固定排序+list All elements are null引起的异常处理+Missing artifact com.sun:tools:jar:1.8.0
Java【问题记录 02】对象封装+固定排序+list All elements are null引起的异常处理+Missing artifact com.sun:tools:jar:1.8.0
43 0
|
9月前
|
Linux
删除大量文件和目录时报错:Argument list too long
这个目录下的文件数量我惊呆了。40W+ 的文件目录数量,直接报错了。
61 1
System.NullReferenceException:“未将对象引用设置到对象的实例。” System.Configuration.ConnectionStringSettingsCollect
System.NullReferenceException:“未将对象引用设置到对象的实例。” System.Configuration.ConnectionStringSettingsCollect
|
11月前
|
安全
Win10需要来自System的权限才能删除的解决方法
经常会遇到想要删除的文件夹和文件无法删除的情况
|
Android开发
Android项目打包遇com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details
原文:Android项目打包遇com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details 版权声明:著作权归作者所有。
5304 0