With following method,
public void setDescription(final String description) {
this.description = description;
if (this.description == null || this.description.isEmpty()) {
this.description = "[description]";
}
}
NetBeans shows a hint on this.description == null
part saying
Unnecessary test for null - the expression is never null
What does this mean? What am I missing?
UPDATE
I have another situation with the same (kind of) hint.
class User {
public void setUsername(final String username) {
if (this.username != null) { // <-- right here!
throw new IllegalStateException(
"already has a username");
}
this.username = username;
}
@NotNull
private String username;
}
NetBeans shows a hint with the same text for the part this.username != null
. In this case NetBeans oversees @NotNull
. Track following issue if you're interested.