Repository navigation
Remove blanket nullness suppressions in google-cloud-platform-core - #40146
Conversation
Replaces the class-level @SuppressWarnings("nullness") on the GCP core module's classes with root-cause nullness fixes, using narrow, documented suppressions only where the null is genuinely valid but the underlying JDK/library stub is not annotated for nullness (exception-constructor null args, Method.invoke null receiver for a static method, URI null fragment, unannotated google-auth Credentials, and constructor/lambda initialization-order the checker cannot follow). Addresses sub-task apache#20498 of the module-level nullness cleanup (apache#20497).
|
Run Java PreCommit |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #40146 +/- ##
============================================
+ Coverage 55.09% 58.45% +3.36%
- Complexity 1722 13590 +11868
============================================
Files 1076 2577 +1501
Lines 171812 269288 +97476
Branches 1262 11080 +9818
============================================
+ Hits 94652 157421 +62769
- Misses 74891 105901 +31010
- Partials 2269 5966 +3697
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @kennknowles for label java. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
R: @kennknowles |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
| @Override | ||
| // fs is null for paths not attached to a filesystem (e.g. created via fromUri/fromComponents); | ||
| // returning it preserves prior behavior. Path.getFileSystem is not annotated for nullness. | ||
| @SuppressWarnings("nullness") |
There was a problem hiding this comment.
Based on the comment, we can have the @SuppressWarnings("nullness") but should also make the return value @Nullable so that downstream consumers will know to check for null.
There was a problem hiding this comment.
@kennknowles Done. Added @nullable to the return type. Kept @SuppressWarnings("nullness") because java.nio.file.Path.getFileSystem() is treated as non-null, so the checker rejects our @nullable override wi
|
|
||
| // AccessDeniedException permits a null "other" argument and these exceptions permit a null detail | ||
| // message, but the JDK constructor stubs are not annotated for nullness. | ||
| @SuppressWarnings("nullness") |
There was a problem hiding this comment.
How about a small helper method like this, to narrow the scope of the suppression. Can reuse in all the methods below as well.
@SuppressWarnings("nullness")
private AccessDeniedException createAccessDeniedException(path, message) [
return new AccessDeniedException(path, null, message)
}
There was a problem hiding this comment.
@kennknowles Done. Extracted helper methods for AccessDeniedException, FileAlreadyExistsException, and FileNotFoundException. This removes the method-level suppressions and limits each suppression to a single constructor call.
…ssions - GcsPath.getFileSystem(): add @nullable to the return type so callers know to null-check. Keep the one-line suppression required by the java.nio.file.Path override (checker treats Path.getFileSystem as @nonnull, so a @nullable override is otherwise rejected). Null-guard the single internal caller. - GcsUtilV1: replace three method-level nullness suppressions with narrow create{AccessDenied,FileAlreadyExists,FileNotFound}Exception helpers that concentrate each suppression to a single JDK constructor call.
kennknowles
left a comment
There was a problem hiding this comment.
Looks good - sorry a git conflict has developed. Hopefully not hard to resolve.
…-20498 # Conflicts: # sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/storage/GcsFileSystem.java
@kennknowles Thanks, resolved (merged master; conflict was with a GCS metrics rewrite in GcsFileSystem.java). Checker-clean, tests pass. |
|
Run Java PreCommit |
|
Thanks @kennknowles conflict resolved, checks green. Merge whenever you have a moment. |
Replaces the class-level
@SuppressWarnings("nullness")on the GCP core module's classes with root-cause nullness fixes, so the module compiles checker-clean without blanket suppression.12 files, checker-clean
compileJava. Existing tests pass (GcsPathTest,GcsResourceIdTest,GcsFileSystemTest,GcsUtilTest: 99 tests, 0 failures).Remaining suppressions
The PR retains 11 narrow, method/statement-scoped
@SuppressWarnings("nullness")annotations, each documented, only where nulls are genuinely valid but third-party or JDK stubs lack nullness annotations:Unannotated JDK Exception Constructors:
other/detail-message arguments onAccessDeniedException,FileAlreadyExistsException,FileNotFoundExceptionGcsUtilV1, the suppressions are concentrated in three one-line factory helpers —createAccessDeniedException,createFileAlreadyExistsException,createFileNotFoundException— reused bygetBucket/createBucket/removeBucket, so no suppression sits on a whole methodOther Unannotated JDK Stubs:
URInull fragment (GcsPath.toUri)Method.invokenull receiver for static methods (GcpSecret)Storage.Objects.rewritenull content body (GcsUtilV1.RewriteOp)Unannotated Libraries:
Credentialsoverrides (NoopCredentialFactory)Overriding a @nonnull JDK Method:
GcsPath.getFileSystemreturns@Nullable(null for detached paths) but overridesjava.nio.file.Path.getFileSystem, which the checker's JDK stub treats as@NonNull; the override cannot loosen the return contract, so the suppression is required alongside the@NullableannotationChecker Initialization-Order Limitation:
thisin supplier lambdas during construction (GcsUtilV1constructor)Fixes #20498
R: @kennknowles
Please add a meaningful description for your change here
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.