Skip to content

Commit 419b733

Browse files
committed
configure jOOQ code-generation to generate nullability annotations
1 parent 05435a9 commit 419b733

20 files changed

Lines changed: 392 additions & 95 deletions

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ make generate-jooq
286286
./gradlew :generated:jooqCodegen
287287
```
288288

289+
The generator writes JSpecify nullability annotations into the generated sources, so NullAway reads the real nullness of every generated method instead of guessing.
290+
Two consequences are worth knowing:
291+
292+
- jOOQ does not officially support the `TYPE_USE` positioning that JSpecify requires yet ([jOOQ/jOOQ#10759](https://github.com/jOOQ/jOOQ/issues/10759)).
293+
The positioning is correct here only because the generated code uses no generics, collections, maps, arrays or forced types with inner
294+
classes.
295+
Keep the `includes` list free of such objects, or review the annotation positions after a regeneration.
296+
- Every generated class carries `@SuppressWarnings({"all", ...})`, which Error Prone honours.
297+
That suppression, and nothing else, is why the generated sources are exempt from the checks in `errorprone.args`, including `RequireExplicitNullMarking`.
298+
Do not add `NullAway:TreatGeneratedAsUnannotated`: it would make NullAway discard the nullability annotations that this generator now writes.
299+
289300
### Docker Environment
290301

291302
See [Docker Environment](docs/docker-environment.md) for setting up a local development environment using Quarkus Dev Services.

generated/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies {
99
*/
1010
api(libs.jooq)
1111
compileOnly(libs.jooqMeta)
12+
compileOnlyApi(libs.jspecify)
1213
// PostgreSQL JDBC Driver for jOOQ generation
1314
jooqCodegen(libs.postgresql)
1415
}
@@ -49,6 +50,14 @@ jooq {
4950
fluentSetters = true
5051
generatedAnnotation = true
5152
pojos = false
53+
nonnullAnnotation = true
54+
nullableAnnotation = true
55+
// We use JSpecify annotations already even though jOOQ does not officially support JSpecify's TYPE_USE positioning yet.
56+
// See https://github.com/jOOQ/jOOQ/issues/10759
57+
// This only works as our generated code is not using any generics, collections, maps, arrays
58+
// or forced types with inner classes, and therefore the positioning of the annotations is accidentally correct.
59+
nonnullAnnotationType = "org.jspecify.annotations.NonNull"
60+
nullableAnnotationType = "org.jspecify.annotations.Nullable"
5261
}
5362
target {
5463
packageName = "it.aboutbits.postgresql.core.infrastructure.persistence"

generated/src/main/java/it/aboutbits/postgresql/core/infrastructure/persistence/DefaultCatalog.java

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/src/main/java/it/aboutbits/postgresql/core/infrastructure/persistence/PgCatalog.java

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/src/main/java/it/aboutbits/postgresql/core/infrastructure/persistence/tables/Aclexplode.java

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/src/main/java/it/aboutbits/postgresql/core/infrastructure/persistence/tables/PgAuthMembers.java

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)