Is it a good practice to have trim in setter?

Posted by zibi on Stack Overflow See other posts from Stack Overflow or by zibi
Published on 2013-11-08T09:46:13Z Indexed on 2013/11/08 9:53 UTC
Read the original article Hit count: 122

Filed under:

I'm doing a code review and I noticed such a code:

@Entity
@Table(name = "SOME_TABLE")
public class SomeReportClass {

@Column(name = "REPORT_NUMBER", length = 6, nullable = false)
private String reportNumber;

.....
    public String getReportNumber() {
        return reportNumber;
    }

    public void setReportNumber(String reportNumber) {
        this.reportNumber = StringUtils.trimToNull(reportNumber);
    }

}

Every time I see trimming inside of a setter I feel that its not the clearest solution - what is the general practice with that issue?

© Stack Overflow or respective owner

Related posts about java