The @NonNegative annotation documents that a numeric parameter cannot be negative. Applied to an index, it can help a static analyzer warn about calls that pass a negative value. section 5.2
Annotating an index
int getValue(@NonNegative int index) { return myData[index]; } The annotation does not replace a runtime bounds check: an index may be nonnegative yet still exceed the array or list bounds. Check client-supplied indexes immediately, and distinguish < from <= when the valid endpoint matters. section 5.2
For an int parameter, JetBrains’ @Range(from = 0, to = Integer.MAX_VALUE) expresses equivalent bounds explicitly. Use annotations to document contracts and aid analysis, not as a substitute for enforcing them. section 5.2
