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
@NonNullByDefault annotations as I can use the synergy with Eclipse to automatically analyse possible
null values and what may lead to
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