Search code examples
javaeclipseeclipse-jdtnon-nullablenull-check

Why does Eclipse JDT Null-Checking respect Apache Commons Validate


I use @NonNull-Checking with Eclipse-JDT and was very pleased to see that it understands and respects the use of Apache Commons Validate. Which means in code:

Validate.notNull(someInput);
@NonNull String a = someInput;

Without the first line the second one produces a warning in Eclipse. I can only configure if "assert" should be respected. But without any further notice it also respects Validate#notNull and Objects#requireNonNull. This is great but I wonder:

  1. Is it hardcoded or configurable (in some plugin, file,...) which frameworks/methods Eclipse respects for proper Null-Checking?
  2. Can I write my own methods to let Eclipse know, some variable is guaranteed to be non-null?

Solution

  • The list is hard coded and can't be extended (other than by modifying the source code).

    Some of the main classes involved as in org.eclipse.jdt.internal.compiler.lookup and org.eclipse.jdt.internal.compiler.ast including the TypeConstants and TypeIds interfaces and the ReferenceBinding and MessageSend classes.