Skip to content

Commit 54b846b

Browse files
authored
docs: add JSpecify nullness guidelines to AGENTS.md (#13881)
This PR adds a dedicated JSpecify Nullness Guidelines section (Section 5) to the repository-wide `AGENTS.md` onboarding guide for AI coding assistants. ### Changes * **Dependency Requirement**: Outlines that JSpecify must be declared in target module POMs. * **Handwritten vs. Generated Modules**: Sets clear guidelines distinguishing handwritten additions from generator-level code composition (`gapic-generator-java`). * **JSpecify Type-Use Semantics**: Establishes class-level `@NullMarked` defaulting, and details specific type-use placement rules for: * Generics (`List<@nullable String> list`) * Arrays (`String @nullable [] array`) * Fully-qualified class names (`com.google.auth.oauth2.@nullable TokenVerifier`)
1 parent 725086d commit 54b846b

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,28 @@ This is a standard Maven project.
4545
4. Avoid unnecessary formatting changes to keep diffs clean.
4646
5. Use `mvn` for everything other than the `test/integration` folder.
4747

48-
## 5. Dependency Management
48+
## 5. Nullness Annotation Guidelines
49+
To enforce compile-time null-safety and eliminate NullPointerExceptions, this repository is adopting JSpecify annotations.
50+
51+
### 5.1 Handwritten vs. Generated Code Handling
52+
- **Handwritten Modules**: Annotations are added to source files directly.
53+
- **Generated Modules**: Do not edit generated class files manually! Instead, update the code generator engine (`gapic-generator-java`) to automatically produce the annotations during the generation phase.
54+
55+
### 5.2 Annotation Usage & Type-Use Semantics
56+
Prefer JSpecify annotations (`org.jspecify.annotations.NullMarked` and `org.jspecify.annotations.Nullable`) over legacy declaration annotations (like `javax.annotation.Nullable`).
57+
- **Default semantics**: Annotate classes with `@NullMarked` to declare that all unannotated types exclude null.
58+
- **Nullable types**: Annotate fields, return types, or parameters with `@Nullable` if they are allowed to be null.
59+
60+
## 6. Dependency Management
4961
- Do not bump external dependency versions unless for CVE or critical bug fix.
5062
- Avoid introducing new external dependencies if possible. Prefer Java standard library, then opt for existing dependencies.
5163

52-
## 6. Contribution Guidelines
64+
## 7. Contribution Guidelines
5365
- **Commits**: Conventional Commits `<type>(<scope>): <description>`.
5466
- **Pull Requests**: Submitted via PR, require review. Pull latest from main and resolve conflicts.
5567
- **Testing**: All new logic should be accompanied by tests.
5668

57-
## 7. Specialized Development Guides
69+
## 8. Specialized Development Guides
5870
For development on core components, refer to the following guides in `sdk-platform-java`:
5971
- **GAPIC Generator**: [sdk-platform-java/gapic-generator-java/DEVELOPMENT.md](sdk-platform-java/gapic-generator-java/DEVELOPMENT.md)
6072
- **GAX**: [sdk-platform-java/gax-java/DEVELOPMENT.md](sdk-platform-java/gax-java/DEVELOPMENT.md)

0 commit comments

Comments
 (0)