I have used the JDT Annotation library in my Java project as I am quite fond of what it offers. To be more exact, I used the @Nullable and @NonNullByDefault annotations as I can use the synergy with Eclipse to automatically analyse possible null values and what may lead to NullPointerException bugs.

Unfortunately, JDT Annotation is licensed under EPL1 which, as far as I know, is incompatible with GPL2 due to the former being a weak copyleft license and choice of some clauses. As the project should be published under a GPL2 license, I am exploring different options but have yet to fine any that would offer the same, or nearly the same, functionality.

I am not keen on adding null checks as they only clutter the code with what an annotation could have solved as well. But unfortunately it seems to be the only viable option? I am looking for some expertise regarding this matter. What I propose is to use Google's Preconditions to formulate preconditions such as:

Preconditions.checkArgument(providedArgument != null, "The provided argument must not be null!");


Preconditions.checkState(invariantField != null, "The field may not be null!");

These will solve the problem of course and be more explicit, in my opinion, when it comes to documenting my contracts by code. I usually also report these with custom tags in my Javadoc, for example, @pre providedArgument != null or @inv invariantField != null.

I would be thankful for all


The null annotations are configurable in Eclipse. You can create your own set of @Null, @NonNull, and @NonNullByDefault annotations, and configure Eclipse to use them instead of standard ones from org.eclipse.jdt.annotation package. See here.

  • The provided link only advertises the use of the org.eclipse.jdt.annotation package. While creating my own set would be possible, they would contain mostly the same code as the one contained in the package. This might be seen as licensing infringement. – Eric Mar 18 '14 at 7:53
  • I really wouldn't worry about that. There is nothing interesting about the annotation declarations themselves. They are just simple declarations. The real work is done by the JDT itself. – Christopher Barber Jun 4 '14 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.