2

Findbugs complains about date objects and suggests creation of defensive copies. I used copies in the constructor and getter method, but it is really necessary to create a defensive copy in setter method? Here is an example:

    public Info(Date created) {
        this.creationDate = new Date(created.getTime());
    }

    public Date getCreated() {
        return new Date(creationDate.getTime());
    }

    public void setCreated(Date created) {
        this.creationDate = created;
    }

Is there a way to get the original object and make changes?

4

2 に答える 2