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

Allow declaration of null safety at package and module level #92

Closed
syrm-ll opened this issue May 8, 2023 · 1 comment
Closed

Allow declaration of null safety at package and module level #92

syrm-ll opened this issue May 8, 2023 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@syrm-ll
Copy link

syrm-ll commented May 8, 2023

broken thoughts

We are looking for a simple and easy-to-use null security solution, but the existing solutions are not satisfactory
Since jsr305 is almost indefinitely shelved, various independent solutions appear in the community, making it difficult to have a unified and easy-to-use API and perfect IDE support

Combining several common solutions, I personally think that the org.springframework.lang solution is the best, comprehensive API ease of use and possible compatibility, but the IDE support is not enough.

question

Consider the following needs:

First of all, should not add annotations to all code, all fields, all parameters! This is the reason why I haven't been able to use jetbrainsAnnotations extensively so far

Use @NonNullApi (scope = parameters + return values) and/or @NonNullFields
(scope = fields) to set the default behavior to non-nullable in order to avoid annotating
your whole codebase with @nonnull.
-- org.springframework.lang.NonNull

  1. By default, the entire module (JPMS module) / entire package / entire class is NotNull or Nullable.
    Separately mark a small number of inconsistent APIs (properties, method parameters, method return values, etc.)
    Similar issue: All parameters NotNull/Nullable #80
  2. By default, all attributes in the entire module (JPMS module) / entire package / entire class are NotNull or Nullable.
    Separately mark a small number of inconsistent APIs (properties, method parameters, method return values, etc.)
  3. By default, all method parameters or return values in the entire module (JPMS module) / entire package / entire class are NotNull or Nullable.
    Separately mark a small number of inconsistent APIs (properties, method parameters, method return values, etc.)

suggestion

org.jetbrains.annotations.NotNull org.jetbrains.annotations.Nullable Modifications:

  • Increase Target ElementType.PACKAGE ElementType.MODULE to satisfy Question 1
  • Added javax.annotation.Nonnull and javax.annotation.Nullable as meta-annotations (optional dependencies) for maximum compatibility
  • Add org.springframework.lang.NonNullApi org.springframework.lang.NonNullFields similar annotations to meet some scenarios in Question 2 and Question 3
  • Add semantic annotations opposite to org.springframework.lang.NonNullApi org.springframework.lang.NonNullFields to meet more flexible scenarios

It is not enough to just modify this repository, it is still necessary for the IDE to provide similar support and allow inspection of javax.annotation.Nonnull similar annotations as meta-annotations for all custom annotations

@amaembo
Copy link
Collaborator

amaembo commented May 8, 2023

Duplicates #53

@amaembo amaembo closed this as completed May 8, 2023
@amaembo amaembo added the duplicate This issue or pull request already exists label May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants