|
| 1 | +The task is to annotate public API classes (marked with `@PublicAPI`) with JSpecify nullability annotations. |
| 2 | + |
| 3 | +Note that JSpecify is already used in this repository so it's already imported. |
| 4 | + |
| 5 | +If you see a builder static class, you can label it `@NullUnmarked` and not need to do anymore for this static class in terms of annotations. |
| 6 | + |
| 7 | +Analyze this Java class and add JSpecify annotations based on: |
| 8 | +1. Set the class to be `@NullMarked` |
| 9 | +2. Remove all the redundant `@NonNull` annotations that IntelliJ added |
| 10 | +3. Check Javadoc @param tags mentioning "null", "nullable", "may be null" |
| 11 | +4. Check Javadoc @return tags mentioning "null", "optional", "if available" |
| 12 | +5. Method implementations that return null or check for null |
| 13 | +6. GraphQL specification details (see details below) |
| 14 | + |
| 15 | +## GraphQL Specification Compliance |
| 16 | +This is a GraphQL implementation. When determining nullability, consult the GraphQL specification (https://spec.graphql.org/draft/) for the relevant concept. Key principles: |
| 17 | + |
| 18 | +The spec defines which elements are required (non-null) vs optional (nullable). Look for keywords like "MUST" to indicate when an element is required, and conditional words such as "IF" to indicate when an element is optional. |
| 19 | + |
| 20 | +If a class implements or represents a GraphQL specification concept, prioritize the spec's nullability requirements over what IntelliJ inferred. |
| 21 | + |
| 22 | +## How to validate |
| 23 | +Finally, please check all this works by running the NullAway compile check. |
| 24 | + |
| 25 | +If you find NullAway errors, try and make the smallest possible change to fix them. If you must, you can use assertNotNull. Make sure to include a message as well. |
| 26 | + |
| 27 | +## Formatting Guidelines |
| 28 | + |
| 29 | +Do not make spacing or formatting changes. Avoid adjusting whitespace, line breaks, or other formatting when editing code. These changes make diffs messy and harder to review. Only make the minimal changes necessary to accomplish the task. |
| 30 | + |
| 31 | +## Cleaning up |
| 32 | +Finally, can you remove this class from the JSpecifyAnnotationsCheck as an exemption |
| 33 | + |
| 34 | +You do not need to run the JSpecifyAnnotationsCheck. Removing the completed class is enough. |
| 35 | + |
| 36 | +Remember to delete all unused imports when you're done from the class you've just annotated. |
| 37 | + |
| 38 | +## Generics Annotations |
| 39 | + |
| 40 | +When annotating generic types and methods, follow these JSpecify rules: |
| 41 | + |
| 42 | +### Type Parameter Bounds |
| 43 | + |
| 44 | +The bound on a type parameter determines whether nullable type arguments are allowed: |
| 45 | + |
| 46 | +| Declaration | Allows `@Nullable` type argument? | |
| 47 | +|-------------|----------------------------------| |
| 48 | +| `<T>` | ❌ No — `Box<@Nullable String>` is illegal | |
| 49 | +| `<T extends @Nullable Object>` | ✅ Yes — `Box<@Nullable String>` is legal | |
| 50 | + |
| 51 | +**When to use `<T extends @Nullable Object>`:** |
| 52 | +- When callers genuinely need to parameterize with nullable types |
| 53 | +- Example: `DataFetcherResult<T extends @Nullable Object>` — data fetchers may return nullable types |
| 54 | + |
| 55 | +**When to keep `<T>`:** |
| 56 | +- When the type parameter represents a concrete non-null object |
| 57 | +- Even if some methods return `@Nullable T` (meaning "can be null even if T is non-null") |
| 58 | +- Example: `Edge<T>` with `@Nullable T getNode()` — node may be null, but T represents the object type |
| 59 | + |
0 commit comments