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

Add nullability annotations to IndexSearcher APIs #14132

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Edarke
Copy link

@Edarke Edarke commented Jan 10, 2025

Annotate public APIs with an internal definition of @Nullable where appropriate.

This proposal is a follow up from the discussion here. This change adds an internal copy of JSpecify's @Nullable to lucene-util and uses Intellij's "infer nullability" feature to automatically apply the annotation to IndexSearcher and its dependencies. If this looks good, there will be a follow up PR to automatically annotate other APIs.

The motivation for this change is to increase the null safety of downstream projects using Lucene by allowing users to configure a javac plugin to lint their build. This change was tested with NullAway, which recognizes any annotation with the simple class name @Nullable

Copy link

This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the [email protected] list. Thank you for your contribution!

@github-actions github-actions bot added the Stale label Jan 25, 2025
@msokolov
Copy link
Contributor

This seems reasonable to me, but it implies a future promise to maintain it, and I don't know how we would ever know if we added some new usage that isn't properly annotated

@rmuir
Copy link
Member

rmuir commented Jan 27, 2025

For the java language:

Specifying that something is nullable doesn't provide any value: all types are nullable by default already.

Specifying that something is NOT-nullable would allow for additional smarts: it is the only possible way to do "gradual nullness typing".

I agree too, that we would need linter to verify this stuff in builds. Maybe the errorprone could do it.

@msokolov
Copy link
Contributor

Specifying that something is nullable doesn't provide any value: all types are nullable by default already.

I guess these null-checking systems impose their own assumptions and assume that anything not annotated with @nullable is not-nullable. Clearly the language doesn't enforce that, but maybe some build-time processor can check for it? Also, the proposal here seems to have been to annotate everything all at once, not gradual, but I agree it seems more sensible to assume everything can be null, indicate @NotNull and then enforce that.

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

Successfully merging this pull request may close these issues.

3 participants