Afaik, annotations can be missing at runtime (even with runtime retention), which will result in the annotation being silently dropped. So if your code compiles, then you're OK even if the VM that is later running your code does not know of the annotation.
In your case, you are using javax.annotation.Nonnull
, which is used by static analysis tools, but usually has no effect at runtime. So yes, you can use it.
In contrast, a hypothetical other annotation whose presence is relevant to your app at runtime, must be present on the classpath.