声纳违规:安全 - 数组直接存储 - 遇到byte []和clone()

时间:2015-06-18 09:04:15

标签: java arrays sonarqube

我在Sonar Violation: Security - Array is stored directly找到了答案 和 Sonar Violation: Security - Array is stored directly when using byte[]

以下是我在Sonar中收到此警告的代码段

byte[] imageBytes;
public DisplayWebThumb(byte[] imageBytes) {
        super(null);
        this.imageBytes = imageBytes;
    }

我查看了解决方案并进行了一些更改。
从这个答案Sonar Violation: Security - Array is stored directly,我做了这个改变

byte[] imageBytes;

public DisplayWebThumb(byte[] imageBytes) {
    super(null);
    if(imageBytes == null){
        this.imageBytes = new byte[0];
    }else {
        this.imageBytes = new byte[imageBytes.length];
        System.arraycopy(imageBytes, 0, this.imageBytes, 0, imageBytes.length);
    }
}

从这个答案Sonar Violation: Security - Array is stored directly when using byte[],我做了这个改变

byte[] imageBytes;  
public DisplayWebThumb(byte[] imageBytes) {
    super(null);
    if(imageBytes == null){
        this.imageBytes = new byte[0];
    }else {
        this.imageBytes = imageBytes.clone();
    }
}

所有解决方案仍然在SonarQube上给我警告。

0 个答案:

没有答案