Skip to content

Remove blanket nullness suppressions in google-cloud-platform-core - #40146

Merged
kennknowles merged 3 commits into
apache:masterfrom
nitinware:nullness-gcp-core-20498
Sep 24, 2026
Merged

kennknowles merged 3 commits into
apache:masterfrom
nitinware:nullness-gcp-core-20498

Conversation

@nitinware

@nitinware nitinware commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Null other/detail-message arguments on AccessDeniedException, FileAlreadyExistsException, FileNotFoundException
  • In GcsUtilV1, the suppressions are concentrated in three one-line factory helpers — createAccessDeniedException, createFileAlreadyExistsException, createFileNotFoundException — reused by getBucket/createBucket/removeBucket, so no suppression sits on a whole method

Other Unannotated JDK Stubs:

  • URI null fragment (GcsPath.toUri)
  • Method.invoke null receiver for static methods (GcpSecret)
  • Storage.Objects.rewrite null content body (GcsUtilV1.RewriteOp)

Unannotated Libraries:

  • google-auth Credentials overrides (NoopCredentialFactory)

Overriding a @nonnull JDK Method:

  • GcsPath.getFileSystem returns @Nullable (null for detached paths) but overrides java.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 @Nullable annotation

Checker Initialization-Order Limitation:

  • Overridable instance method calls capturing this in supplier lambdas during construction (GcsUtilV1 constructor)

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:

  • Mention the appropriate issue in your description (for example: 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, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

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)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

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).
@nitinware
nitinware marked this pull request as ready for review September 17, 2026 02:06
@nitinware

Copy link
Copy Markdown
Contributor Author

Run Java PreCommit

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.78873% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.45%. Comparing base (bdf650a) to head (debaabe).
⚠️ Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
...beam/sdk/extensions/gcp/storage/GcsFileSystem.java 8.33% 11 Missing ⚠️
...apache/beam/sdk/extensions/gcp/util/GcsUtilV1.java 60.71% 9 Missing and 2 partials ⚠️
...he/beam/sdk/extensions/gcp/util/gcsfs/GcsPath.java 84.61% 1 Missing and 1 partial ⚠️
.../extensions/gcp/options/GoogleApiDebugOptions.java 75.00% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
java 64.68% <64.78%> (-3.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

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 assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@kennknowles

Copy link
Copy Markdown
Member

R: @kennknowles

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nitinware nitinware Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}

@nitinware nitinware Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 kennknowles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@nitinware

Copy link
Copy Markdown
Contributor Author

Looks good - sorry a git conflict has developed. Hopefully not hard to resolve.

@kennknowles Thanks, resolved (merged master; conflict was with a GCS metrics rewrite in GcsFileSystem.java). Checker-clean, tests pass.

@nitinware

Copy link
Copy Markdown
Contributor Author

Run Java PreCommit

@nitinware

Copy link
Copy Markdown
Contributor Author

Thanks @kennknowles conflict resolved, checks green. Merge whenever you have a moment.

@kennknowles
kennknowles merged commit 3afe19a into apache:master Sep 24, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate nullability errors from :sdks:java:extensions:google-cloud-platform-core

2 participants