Java 声纳违规:安全-数组直接存储-字节[]和克隆()有问题

Java 声纳违规:安全-数组直接存储-字节[]和克隆()有问题,java,arrays,sonarqube,Java,Arrays,Sonarqube,我找到了答案 和 下面是我在Sonar中得到此警告的代码片段 byte[] imageBytes; public DisplayWebThumb(byte[] imageBytes) { super(null); this.imageBytes = imageBytes; } 我查看了解决方案,并做了一些更改。 根据这个答案,我做了如下更改 byte[] imageBytes; public DisplayWebThumb(byte[] imageB

我找到了答案 和

下面是我在Sonar中得到此警告的代码片段

byte[] imageBytes;
public DisplayWebThumb(byte[] imageBytes) {
        super(null);
        this.imageBytes = imageBytes;
    }
我查看了解决方案,并做了一些更改。
根据这个答案,我做了如下更改

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);
    }
}
byte[] imageBytes;  
public DisplayWebThumb(byte[] imageBytes) {
    super(null);
    if(imageBytes == null){
        this.imageBytes = new byte[0];
    }else {
        this.imageBytes = imageBytes.clone();
    }
}
根据这个答案,我做出了这样的改变

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);
    }
}
byte[] imageBytes;  
public DisplayWebThumb(byte[] imageBytes) {
    super(null);
    if(imageBytes == null){
        this.imageBytes = new byte[0];
    }else {
        this.imageBytes = imageBytes.clone();
    }
}

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

Hi-我已经标记为重复,因为您已经在上的其他地方详细说明了答案SO@BrianAgnew其他答案显然没有解决他的问题。@BrianAgnew我查看了解决方案,但仍然得到了警告。。请仔细看我的问题。我已经重新开始,但你可能需要重新措辞