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 nonnull annotations for PolarisEntityManager public constructor #573

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chenjian2664
Copy link
Contributor

No description provided.

@chenjian2664 chenjian2664 changed the title Add nonnull annotations for public constructor Add nonnull annotations for PolarisEntityManager public constructor Dec 17, 2024
@adutra
Copy link
Contributor

adutra commented Dec 19, 2024

@chenjian2664 I'm not sure we want to go in this direction. I think that instead we should assume that in all Polaris code, parameters and return types are non-null by default, and only annotate the nullable ones. WDYT?

@flyrain
Copy link
Contributor

flyrain commented Dec 20, 2024

I believe it's appropriate to apply the @Nonnull annotation to these parameters. By checking these fields, they are indeed expected to be non-null. This annotation will make the intent explicit and enhance both code clarity and safety. With that, +1 on the PR.

@chenjian2664
Copy link
Contributor Author

@adutra Thanks for the reply.

I think that instead we should assume that in all Polaris code, parameters and return types are non-null by default

In this case, explicit check would make code more safe just as @flyrain mentioned.

and only annotate the nullable ones.

The current code base seems do the both the explicit check for null and nonnull in most places

@adutra
Copy link
Contributor

adutra commented Dec 26, 2024

@flyrain and @chenjian2664 I don't mind adding these annotations, but if we think globally about Polaris code, and assuming that, since the API is biased towards non-nullability by default, about 80% of method arguments and method return types are non-null, annotating each and every one of them will quickly become a visual clutter.

Instead, there are better options to mark an API as "non-null by default", e.g. using JSR 305 annotation @ParametersAreNonnullByDefault placed at package level. Most IDEs are capable of understanding that and would automatically enforce non-nullability everywhere.

@dimas-b
Copy link
Contributor

dimas-b commented Dec 27, 2024

I support using the "non-null by default" convention in APIs.

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

Successfully merging this pull request may close these issues.

4 participants