Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] nullchecks in array elements #2271

Closed
Coada opened this issue Oct 23, 2019 · 1 comment
Closed

[FEATURE] nullchecks in array elements #2271

Coada opened this issue Oct 23, 2019 · 1 comment

Comments

@Coada
Copy link

Coada commented Oct 23, 2019

Hello,

I am interested in the feature of using @NonNull on an array, such that the array's elements are also being checked. Optionally using something such as @NonNullElements might be introduced to not modify how @NonNull operates.

@NonNull String[] stringArray;

stringArray = null; // NOK
stringArray = new String[]{null}; // NOK

I believe this is related to #2019 and specifically #2019 (comment)

The benefits would be for developers who mistakenly think they are safe from doing null-checking on the elements themselves. Despite having all these null-checking annotations as help, a developer must still do these checks to be safe.

@rzwitserloot
Copy link
Collaborator

rzwitserloot commented Jan 15, 2020

Too specific, not boilerplate. I also think that developers presuming that @NonNull on an array implies that individual elements also cannot be null is bizarre and not worth catering to. It is nonsensical to think this. Specifically:

  • arrays of non-primitive types are obsolete. Do not use these in your codebase; use List<String> instead.
  • There are type-use annotations; String @NonNull [] is more appropriate (but adding explicit nullcheck code to this is not a good idea; whilst for arrays lombok would know how, for something like List<@NonNull String> lombok would not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants