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

Annotate the rest of the main package (basically just the Java 8 subjects) for nullness. #1321

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

copybara-service[bot]
Copy link
Contributor

Annotate the rest of the main package (basically just the Java 8 subjects) for nullness.

And move the @NullMarked annotation from individual classes up to the package.

Motivation:

  • The annotating is about potentially making things nicer for callers (or any future J2KT use?).
  • Moving @NullMarked to the package is about saving Truth users from a warning when running Error Prone with --release 8: When @NullMarked appears on a class, Error Prone processes the entire NullMarked class in order to check whether NullMarked is @Inherited. This leads to warning: unknown enum constant ElementType.MODULE because NullMarked has @Target(MODULE, ...) but MODULE isn't available until Java 9. We'll also be fixing this on the Error Prone side, but we might as well work around it on the Truth side, too—and annotate the rest of Truth while we're at it.

(In principle, I should now add @NullUnmarked to all of Truth's test classes, since they haven't been annotated. But doing so would have little to no effect in practice unless maybe IntelliJ recognizes @NullUnmarked (probably not now?) or we improve our nullness offerings in Error Prone. I'm planning to not bother, but let me know if I'm being overly lazy.)

Note that this CL applies @Nullable to some assertion methods' parameters even though those assertions would always fail if the callers passed null. This follows a principle that we'd applied (albeit incompletely) in cl/516515683, which showed that such changes avoided producing build errors in existing, working code. The principle is the same as that discussed for EqualsTester in cl/578260904.

Fixes #1320

RELNOTES=Annotated the rest of the main package for nullness, and moved the @NullMarked annotation from individual classes up to the package to avoid a warning under --release 8.

…ects) for nullness.

And move the `@NullMarked` annotation from individual classes up to the package.

Motivation:
- The annotating is about potentially making things nicer for callers (or any future J2KT use?).
- Moving `@NullMarked` to the package is about saving Truth users from [a warning when running Error Prone with `--release 8`](#1320): When `@NullMarked` appears on a _class_, Error Prone processes the entire `NullMarked` class in order to check whether `NullMarked` is `@Inherited`. This leads to `warning: unknown enum constant ElementType.MODULE` because `NullMarked` has `@Target(MODULE, ...)` but `MODULE` isn't available until Java 9. We'll also be fixing this on the Error Prone side, but we might as well work around it on the Truth side, too—and annotate the rest of Truth while we're at it.

(In principle, I should now add `@NullUnmarked` to all of Truth's test classes, since they haven't been annotated. But doing so would have little to no effect in practice unless maybe IntelliJ recognizes `@NullUnmarked` (probably not now?) or we improve our nullness offerings in Error Prone. I'm planning to not bother, but let me know if I'm being overly lazy.)

Note that this CL applies `@Nullable` to some assertion methods' parameters even though those assertions would always fail if the callers passed `null`. This follows a principle that we'd applied (albeit incompletely) in cl/516515683, which showed that such changes avoided producing build errors in existing, working code. The principle is the same as that discussed for `EqualsTester` in cl/578260904.

Fixes #1320

RELNOTES=Annotated the rest of the main package for nullness, and moved the `@NullMarked` annotation from individual classes up to the package to avoid [a warning under `--release 8`](#1320).
PiperOrigin-RevId: 651891918
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.

unknown enum constant ElementType.MODULE with Truth 1.4.3
1 participant