I'm working in an old project with some old code and findbug is giving the following error with a byte[].
FindBugs: May expose internal representation by incorporating reference to mutable object 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 u nchecked 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.
I'm wondering if someone could help me to understand the proper way to handle this error?
private byte[] fileContent;
public FileUpload(String fileName, String fileExtension, long fileSize, byte[] fileContent, boolean attachedToPo, boolean programOwner) {
this.fileName = fileName;
this.fileExtension = fileExtension;
this.fileSize = fileSize;
this.fileContent = fileContent;
this.attachedToPo = attachedToPo;
this.programOwner = programOwner;
}
public byte[] getFileContent() {
return fileContent;
}
public void setFileContent(byte[] fileContent) {
this.fileContent = fileContent;
}
EDIT I understand why the bug exist and I know how to deal with this when it comes to dates etc. I'm just a little confused with how to deal with it when it comes to byte[].