Skip to content

Commit

Permalink
Promote @ElementTypesAreNonnullByDefault to the package level, repl…
Browse files Browse the repository at this point in the history
…acing `@ParametersAreNonnullByDefault`.

We've annotated individual classes that haven't been annotated for nullness as `@NullUnmarked`. That will likely take precedence over `@ElementTypesAreNonnullByDefault`. Even if it does not, it will take precedence over `@NullMarked`, to which we will be migrating soon.

I normally recommend annotating individual classes with `@NullMarked`, rather than packages. However, because Guava supports Java 8, and because users sometimes use reflection to inspect arbitrary annotations on Guava's classed (such as by using Mockito to mock them), there is some [danger](https://github.com/jspecify/jspecify/wiki/version-compatibility#runtime) in annotating individual classes with `@NullMarked`, whose [`@Target` includes `MODULE`](https://jspecify.dev/docs/api/org/jspecify/annotations/NullMarked.html), which isn't available under Java 8.

RELNOTES=n/a
PiperOrigin-RevId: 708300606
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 20, 2024
1 parent cc2c5d3 commit 5fe9d20
Show file tree
Hide file tree
Showing 71 changed files with 109 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
* href="https://github.com/google/guava">Guava</a> library.
*/
@com.google.errorprone.annotations.CheckReturnValue
@javax.annotation.ParametersAreNonnullByDefault
package com.google.common.testing;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/base/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@
* Defaults}), as well as a number of classes that have been superseded by additions to the JDK.
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.base;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/cache/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
* @author Charles Fry
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.cache;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@
* </ul>
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.collect;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/escape/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* library.
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.escape;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* href="https://github.com/google/guava/wiki/EventBusExplained">{@code EventBus}</a>.
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.eventbus;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/graph/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
* library.
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.graph;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/hash/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
* href="https://github.com/google/guava/wiki/HashingExplained">hashing</a>.
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.hash;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/html/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
* library.
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.html;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/io/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
* @author Chris Nokleberg
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.io;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/math/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
* <p>See the Guava User Guide article on <a
* href="https://github.com/google/guava/wiki/MathExplained">math utilities</a>.
*/
@ParametersAreNonnullByDefault
@CheckReturnValue
@ElementTypesAreNonnullByDefault
package com.google.common.math;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
3 changes: 1 addition & 2 deletions android/guava/src/com/google/common/net/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
* @author Craig Berry
*/
@CheckReturnValue
@ParametersAreNonnullByDefault
@ElementTypesAreNonnullByDefault
package com.google.common.net;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -35,7 +36,7 @@
*/
@GwtCompatible
@Retention(RUNTIME)
@Target(TYPE)
@Target({PACKAGE, TYPE})
@TypeQualifierDefault({FIELD, METHOD, PARAMETER})
@Nonnull
@interface ElementTypesAreNonnullByDefault {}
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@
* <li>{@link Primitives}
* </ul>
*/
@ParametersAreNonnullByDefault
@CheckReturnValue
@ElementTypesAreNonnullByDefault
package com.google.common.primitives;

import com.google.errorprone.annotations.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
Loading

0 comments on commit 5fe9d20

Please sign in to comment.