Skip to content

[ErrorProne] enable JavaUtilDate, TimeUnitConversionChecker, InvalidThrows checks#37791

Draft
stankiewicz wants to merge 1 commit intoapache:masterfrom
stankiewicz:error_prone_bulk2
Draft

[ErrorProne] enable JavaUtilDate, TimeUnitConversionChecker, InvalidThrows checks#37791
stankiewicz wants to merge 1 commit intoapache:masterfrom
stankiewicz:error_prone_bulk2

Conversation

@stankiewicz
Copy link
Contributor

  1. enable JavaUtilDate, TimeUnitConversionChecker, InvalidThrows checks
  2. fix all violations

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances code quality and maintainability by activating three new ErrorProne checks: JavaUtilDate, TimeUnitConversionChecker, and InvalidThrows. The changes involve a widespread migration from the legacy java.util.Date API to the more modern and robust java.time package, improving date and time handling across the codebase. Additionally, unnecessary @throws declarations were removed, and specific warnings were suppressed where appropriate, ensuring a cleaner and more accurate codebase.

Highlights

  • ErrorProne Checks Enabled: Enabled three new ErrorProne checks: "JavaUtilDate", "TimeUnitConversionChecker", and "InvalidThrows", by removing them from the suppressed checks list in the build configuration.
  • Java Date/Time API Modernization: Addressed numerous violations of the "JavaUtilDate" check by migrating usage of the legacy java.util.Date API to the modern java.time package (e.g., LocalDateTime, Instant) across various files.
  • Javadoc Cleanup: Resolved "InvalidThrows" violations by removing unnecessary @throws declarations from Javadoc comments in several methods.
  • Warning Suppressions: Introduced @SuppressWarnings annotations for "JavaUtilDate" and "TimeUnitConversionChecker" in specific instances where immediate migration was not feasible or where the usage was deemed acceptable for testing/logging purposes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy
    • Removed "InvalidThrows", "JavaUtilDate", and "TimeUnitConversionChecker" from the list of suppressed ErrorProne checks, effectively enabling them.
    • Corrected duplicate entries for "InvalidParam" and "JavaTimeDefaultTimeZone" in the suppressed checks list.
  • examples/java/src/main/java/org/apache/beam/examples/complete/datatokenization/utils/SchemasUtils.java
    • Removed an unnecessary @throws IOException from the getGcsFileAsString method's Javadoc.
  • examples/java/src/test/java/org/apache/beam/examples/WindowedWordCountIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp generation in test output filenames.
  • examples/java/src/test/java/org/apache/beam/examples/WordCountIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp generation in test output filenames.
  • examples/java/src/test/java/org/apache/beam/examples/complete/TfIdfIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp generation in test output filenames.
  • examples/java/src/test/java/org/apache/beam/examples/complete/TopWikipediaSessionsIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp generation in test output filenames.
  • examples/java/src/test/java/org/apache/beam/examples/cookbook/DistinctExampleIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp generation in test output filenames.
  • examples/java/src/test/java/org/apache/beam/examples/cookbook/JoinExamplesIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp generation in test output filenames.
  • examples/java/twitter/src/main/java/org/apache/beam/examples/twitterstreamgenerator/ReadFromTwitterDoFn.java
    • Updated Instant.ofEpochMilli to correctly convert status.getCreatedAt() from java.util.Date to Instant using toInstant().toEpochMilli().
  • examples/java/twitter/src/test/java/org/apache/beam/examples/twitterstreamgenerator/ReadFromTwitterDoFnTest.java
    • Added @SuppressWarnings("JavaUtilDate") to the setUp method to suppress the ErrorProne warning.
  • it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/dataflow/DirectRunnerClient.java
    • Removed java.util.Date import and replaced its usage with java.time.Instant.now().toEpochMilli() for job ID generation.
  • runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/MetricsLogger.java
    • Removed java.util.Date import and replaced its usage with java.time.Instant.ofEpochMilli() for logging the last reported time.
  • runners/flink/2.0/src/test/java/org/apache/beam/runners/flink/FlinkRequiresStableInputTest.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for output directory naming in tests.
  • runners/flink/src/test/java/org/apache/beam/runners/flink/FlinkRequiresStableInputTest.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for output directory naming in tests.
  • runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/logging/DataflowWorkerLoggingHandler.java
    • Added @SuppressWarnings("JavaUtilDate") to the get method of FileOutputStreamFactory.
  • runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/StreamingDataflowWorkerTest.java
    • Added @SuppressWarnings("TimeUnitConversionChecker") to the class declaration to suppress the ErrorProne warning.
  • runners/java-fn-execution/src/main/java/org/apache/beam/runners/fnexecution/artifact/ArtifactStagingService.java
    • Removed an unnecessary @throws IOException from the offer method's Javadoc.
  • sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/TransformUpgrader.java
    • Removed an unnecessary @throws Exception from the upgradeTransformsViaTransformService method's Javadoc.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/RequiresStableInputIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for output directory naming in tests.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/testing/TestPipelineTest.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for timestamp formatting in a Hamcrest matcher.
  • sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/GcsUtilIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for filename generation in tests.
  • sdks/java/extensions/sql/jdbc/src/test/java/org/apache/beam/sdk/extensions/sql/jdbc/BeamSqlLineIT.java
    • Added @SuppressWarnings("JavaUtilDate") to the convertTimestampToMillis method.
  • sdks/java/extensions/zetasketch/src/test/java/org/apache/beam/sdk/extensions/zetasketch/BigQueryHllSketchCompatibilityIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for dataset ID generation in tests.
  • sdks/java/io/azure/src/main/java/org/apache/beam/sdk/io/azure/blobstore/AzureBlobStoreFileSystem.java
    • Added @SuppressWarnings("JavaUtilDate") to the generateSasToken method.
  • sdks/java/io/common/src/main/java/org/apache/beam/sdk/io/common/DatabaseTestHelper.java
    • Replaced java.util.Date and SimpleDateFormat with java.time.LocalDateTime, java.time.ZoneId, and java.time.format.DateTimeFormatter for test table name generation.
  • sdks/java/io/file-based-io-tests/src/test/java/org/apache/beam/sdk/io/common/FileBasedIOITHelper.java
    • Removed java.util.Date import and replaced its usage with java.time.Instant.now().toEpochMilli() for timestamp suffix appending.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
    • Removed unnecessary @throws ParseException and @throws IOException declarations from method Javadoc.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/mapper/ChangeStreamRecordMapper.java
    • Removed an unnecessary @throws InvalidProtocolBufferException from the toChangeStreamRecords method's Javadoc.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableReadIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for table ID generation in tests.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableReadSchemaTransformProviderIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for table ID generation in tests.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableServiceImplTest.java
    • Removed unnecessary @throws InterruptedException declarations from method Javadoc.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableSimpleWriteSchemaTransformProviderIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for table ID generation in tests.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableWriteIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for table ID generation in tests.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigtable/BigtableWriteSchemaTransformProviderIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for table ID generation in tests.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/datastore/DatastoreV1Test.java
    • Added @SuppressWarnings("JavaUtilDate") to the makeLatestTimestampResponse method.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/storage/GcsKmsKeyIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for filename generation in tests.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/storage/GcsMatchIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for folder naming in tests.
  • sdks/java/io/influxdb/src/test/java/org/apache/beam/sdk/io/influxdb/InfluxDbIOTest.java
    • Added @SuppressWarnings("JavaUtilDate") to the mockResult method.
  • sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcUtil.java
    • Added @SuppressWarnings("JavaUtilDate") to the getPreparedStatementSetCaller method.
  • sdks/java/io/jdbc/src/test/java/org/apache/beam/sdk/io/jdbc/JdbcIOTest.java
    • Added @SuppressWarnings("JavaUtilDate") to the testGetPreparedStatementSetCallerForLogicalTypes method.
    • Updated setTimestamp call to use cal.getTimeInMillis() instead of cal.getTime().getTime().
  • sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbGridFSIO.java
    • Updated Instant creation to use toInstant().toEpochMilli() for gridFSFile.getUploadDate().
  • sdks/java/io/mongodb/src/test/java/org/apache/beam/sdk/io/mongodb/MongoDBIOIT.java
    • Removed java.util.Date import and replaced its usage with java.time.Instant.now().toEpochMilli() for collection naming in tests.
  • sdks/java/io/rabbitmq/src/main/java/org/apache/beam/sdk/io/rabbitmq/RabbitMqMessage.java
    • Added @SuppressWarnings("JavaUtilDate") to three constructors (RabbitMqMessage(byte[] body), RabbitMqMessage(String routingKey, GetResponse delivery), RabbitMqMessage(String routingKey, byte[] body, AMQP.BasicProperties props)).
  • sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/SnowflakeIO.java
    • Replaced java.util.Date and SimpleDateFormat with java.time.LocalDateTime, java.time.ZoneId, and java.time.format.DateTimeFormatter for temporary directory naming.
  • sdks/java/testing/jpms-tests/src/test/java/org/apache/beam/sdk/jpmstests/JpmsIT.java
    • Replaced java.util.Date imports and usage with java.time.LocalDateTime and java.time.ZoneId for output directory naming in tests.
  • sdks/java/testing/tpcds/src/main/java/org/apache/beam/sdk/tpcds/BeamSqlEnvRunner.java
    • Added @SuppressWarnings("JavaUtilDate") to the printExecutionSummary method.
  • sdks/java/testing/tpcds/src/main/java/org/apache/beam/sdk/tpcds/SqlTransformRunner.java
    • Added @SuppressWarnings("JavaUtilDate") to the printExecutionSummary method.
  • sdks/java/testing/tpcds/src/main/java/org/apache/beam/sdk/tpcds/TpcdsParametersReader.java
    • Removed unnecessary @throws Exception declarations from method Javadoc.
  • sdks/java/testing/tpcds/src/main/java/org/apache/beam/sdk/tpcds/TpcdsRunResult.java
    • Added @SuppressWarnings("JavaUtilDate") to the getStartDate and getEndDate methods.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@stankiewicz stankiewicz marked this pull request as draft March 6, 2026 20:22
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.75%. Comparing base (298f309) to head (6b70ec9).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #37791      +/-   ##
============================================
- Coverage     56.87%   54.75%   -2.12%     
+ Complexity     3417     1690    -1727     
============================================
  Files          1178     1063     -115     
  Lines        187492   166917   -20575     
  Branches       3590     1227    -2363     
============================================
- Hits         106628    91398   -15230     
+ Misses        77472    73321    -4151     
+ Partials       3392     2198    -1194     
Flag Coverage Δ
java 67.35% <ø> (-4.61%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

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.

1 participant