I have implements spot bugs in my project and it is continuously giving me an error for following code -filed DATE.
What I need to do is exclude generating getters and setters for the createTime and UpdateTime fields. Because I am going to clone the date object.
@Getter
@Setter
@MappedSuperclass
public class BaseErrorMessageDto implements Serializable {
@Getter(AccessLevel.PRIVATE)
private Date createTime;
@Getter(AccessLevel.PRIVATE)
private Date updateTime;
public Date getCreateTime() {
return (Date) createTime.clone();
}
public Date getUpdateTime() {
return (Date) updateTime.clone();
}
}
Giving The following error
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 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.
What I need to do is exclude generating getters and setters for the createTime and UpdateTime fields.