I found answer in Sonar Violation: Security - Array is stored directly and Sonar Violation: Security - Array is stored directly when using byte[]
Following is the code snippet for which I get this warning in Sonar
byte[] imageBytes;
public DisplayWebThumb(byte[] imageBytes) {
super(null);
this.imageBytes = imageBytes;
}
I looked at the solutions and made few changes.
From this answer Sonar Violation: Security - Array is stored directly , I made this changes
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);
}
}
From this answer Sonar Violation: Security - Array is stored directly when using byte[] , I made this changes
byte[] imageBytes;
public DisplayWebThumb(byte[] imageBytes) {
super(null);
if(imageBytes == null){
this.imageBytes = new byte[0];
}else {
this.imageBytes = imageBytes.clone();
}
}
All the solutions still give me warning in SonarQube.