Browse Source
When using @NonNull annotations in new code, if I write public void setFrobber(@NonNull frobber) { this.frobber = frobber; } then consumers of the JGit library that do not have nullness checking enabled can easily pass in null by mistake. On the other hand, if I write public void setFrobber(@NonNull frobber) { if (frobber == null) { throw new NullPointerException(); } this.frobber = frobber; } then Eclipse JDT complains: Null comparison always yields false: The variable frobber is specified as @NonNull Add a checkNotNull helper that offers the best of both worlds: public void setFrobber(@NonNull frobber) { this.frobber = checkNotNull(frobber); } Briefer code, null check is intact, and no warning. Inspired by Guava's com.google.common.base.Preconditions.checkNotNull. Change-Id: If59588d13a1119e899657ed2296931ea18ed0e2astable-5.4
Jonathan Nieder
6 years ago
2 changed files with 28 additions and 4 deletions
Loading…
Reference in new issue