Malicious code vulnerability - May expose internal representation by incorporating reference to mutable object

后端 未结 8 1615
遇见更好的自我
遇见更好的自我 2020-11-27 05:00

I have the following code in my dto class.

public void setBillDate(Date billDate) {
    this.billDate = billDate;
}

And I get an error in s

8条回答
  •  长情又很酷
    2020-11-27 05:35

    In addition to the existing answers, I propose a new version based on Optional class from Java 8.

    public void setBillDate(Date billDate) {
        this.billDate = Optional
                .ofNullable(billDate)
                .map(Date::getTime)
                .map(Date::new)
                .orElse(null);
    }
    

提交回复
热议问题