Skip to content

[ErrorProne] Enable BadImport ErrorProne check and fix violations#37760

Open
stankiewicz wants to merge 3 commits intoapache:masterfrom
stankiewicz:error_prone_badImportCheck
Open

[ErrorProne] Enable BadImport ErrorProne check and fix violations#37760
stankiewicz wants to merge 3 commits intoapache:masterfrom
stankiewicz:error_prone_badImportCheck

Conversation

@stankiewicz
Copy link
Contributor

This PR removes the BadImport check from disabledChecks in BeamModulePlugin.groovy to enforce clearer import practices in the codebase.
The BadImport rule prevents importing nested classes or static methods with overly common names (such as Type, Builder, State, etc.) directly, which can make code hard to read out of context. Instead, it encourages qualifying the name with the containing class.
Changes include:

  • Build: Removed BadImport from the disabledChecks list in BeamModulePlugin.
  • Refactoring: Replaced unqualified imports with their qualified parent prefixes across modules that failed compilation.
  • Affected Areas: sdks/java/core, sdks/java/extensions (Avro, Euphoria), sdks/java/io (GCP/BigQuery/Bigtable, Snowflake), and runners (Dataflow, Spark, JobService, fn-execution).

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 aims to improve code readability and maintainability by enforcing a stricter import style. It activates the BadImport ErrorProne check, which prevents direct imports of commonly named nested classes or static methods, thereby encouraging developers to use fully qualified names. This change was systematically applied across various modules to resolve the newly enforced rule violations.

Highlights

  • ErrorProne Check Enabled: The BadImport ErrorProne check has been enabled across the codebase to enforce clearer import practices.
  • Import Violations Fixed: Violations of the BadImport rule were fixed by replacing unqualified imports of nested classes or static methods with their fully qualified parent prefixes.
  • Affected Modules: Changes were applied to sdks/java/core, sdks/java/extensions (Avro, Euphoria), sdks/java/io (GCP/BigQuery/Bigtable, Snowflake), and runners (Dataflow, Spark, JobService, fn-execution).

🧠 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 "BadImport" from the list of disabled ErrorProne checks.
  • runners/google-cloud-dataflow-java/worker/src/test/java/org/apache/beam/runners/dataflow/worker/StreamingDataflowWorkerTest.java
    • Removed an unqualified import for Windmill.Timer.Type.
    • Qualified the usage of Type.WATERMARK to Windmill.Timer.Type.WATERMARK.
  • runners/java-fn-execution/src/test/java/org/apache/beam/runners/fnexecution/control/DefaultJobBundleFactoryTest.java
    • Removed an unqualified import for EnvironmentFactory.Provider.
    • Qualified the type declaration for Map<String, Provider> to Map<String, EnvironmentFactory.Provider>.
  • runners/java-job-service/src/main/java/org/apache/beam/runners/jobsubmission/JobInvocation.java
    • Removed an unqualified import for JobApi.JobState.Enum.
    • Qualified references to Enum.DONE, Enum.RUNNING, Enum.CANCELLED, Enum.FAILED with JobState.Enum.
  • runners/spark/3/src/main/java/org/apache/beam/runners/spark/structuredstreaming/translation/helpers/EncoderHelpers.java
    • Removed a static import for EncoderFactory.newInstance.
    • Qualified the newInstance method call with EncoderFactory.
  • runners/spark/src/main/java/org/apache/beam/runners/spark/util/CachedSideInputReader.java
    • Removed unqualified imports for SideInputStorage.Key and SideInputStorage.Value.
    • Qualified the usage of Key and Value with SideInputStorage.
  • sdks/java/core/src/main/java/org/apache/beam/sdk/fn/channel/AddHarnessIdInterceptor.java
    • Removed an unqualified import for Metadata.Key.
    • Qualified the declaration of ID_KEY with Metadata.Key.
  • sdks/java/core/src/main/java/org/apache/beam/sdk/fn/server/GrpcContextHeaderAccessorProvider.java
    • Removed an unqualified import for Metadata.Key.
    • Qualified the declaration of WORKER_ID_KEY with Metadata.Key.
  • sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtils.java
    • Removed an unqualified import for Schema.Type.
    • Qualified all references to Type with org.apache.avro.Schema.Type.
  • sdks/java/extensions/avro/src/test/java/org/apache/beam/sdk/extensions/avro/schemas/utils/AvroUtilsTest.java
    • Removed an unqualified import for Schema.Type.
    • Qualified all references to Type with org.apache.avro.Schema.Type in test cases.
  • sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/client/operator/FullJoin.java
    • Removed an unqualified import for Join.Type.
    • Qualified the usage of Type.FULL with Join.Type.FULL.
  • sdks/java/extensions/euphoria/src/main/java/org/apache/beam/sdk/extensions/euphoria/core/client/operator/RightJoin.java
    • Removed an unqualified import for Join.Type.
    • Qualified the usage of Type.RIGHT with Join.Type.RIGHT.
  • sdks/java/extensions/euphoria/src/test/java/org/apache/beam/sdk/extensions/euphoria/core/translate/SingleJvmAccumulatorProviderTest.java
    • Removed an unqualified import for SingleJvmAccumulatorProvider.Factory.
    • Qualified the declaration of accFactory with SingleJvmAccumulatorProvider.Factory.
  • sdks/java/extensions/euphoria/src/test/java/org/apache/beam/sdk/extensions/euphoria/core/translate/collector/SingleValueCollectorTest.java
    • Removed an unqualified import for SingleJvmAccumulatorProvider.Factory.
    • Qualified the declaration of accumulatorFactory with SingleJvmAccumulatorProvider.Factory.
  • sdks/java/io/gcp/bigtable/BigtableSharedClientTest.java
    • Removed an unqualified import for BigtableDataSettings.Builder.
    • Qualified the generic type and method signature with BigtableDataSettings.Builder.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryAvroUtils.java
    • Removed an unqualified import for Schema.Type.
    • Qualified references to Type with Schema.Type.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiWriteUnshardedRecords.java
    • Removed an unqualified import for WriteStream.Type.
    • Qualified the usage of Type.PENDING with WriteStream.Type.PENDING.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/StorageApiWritesShardedRecords.java
    • Removed an unqualified import for WriteStream.Type.
    • Qualified the usage of Type.BUFFERED with WriteStream.Type.BUFFERED.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/TableRowToStorageApiProto.java
    • Removed an unqualified import for FieldDescriptorProto.Type.
    • Qualified references to Type with FieldDescriptorProto.Type in type maps and field descriptors.
  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/testing/FakeDatasetService.java
    • Removed an unqualified import for WriteStream.Type.
    • Qualified references to Type with WriteStream.Type in class fields and method calls.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/AvroGenericRecordToStorageApiProtoTest.java
    • Removed an unqualified import for FieldDescriptorProto.Type.
    • Qualified references to Type with FieldDescriptorProto.Type in field descriptors and type maps.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BeamRowToStorageApiProtoTest.java
    • Removed an unqualified import for FieldDescriptorProto.Type.
    • Qualified references to Type with FieldDescriptorProto.Type in field descriptors and type maps.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIOWriteTest.java
    • Removed a static import for WriteTables.ResultCoder.INSTANCE.
    • Instantiated WriteTables.ResultCoder directly in setCoder.
    • Qualified WriteTables.ResultCoder.INSTANCE in IterableCoder.of.
  • sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/TableRowToStorageApiProtoTest.java
    • Removed an unqualified import for FieldDescriptorProto.Type.
    • Qualified references to Type with FieldDescriptorProto.Type in field descriptors and type maps.
  • sdks/java/io/snowflake/src/main/java/org/apache/beam/sdk/io/snowflake/data/SnowflakeDataType.java
    • Removed an unqualified import for JsonSubTypes.Type.
    • Qualified the usage of Type within @JsonSubTypes annotation with JsonSubTypes.Type.
Activity
  • The pull request was initiated to enable the BadImport ErrorProne check.
  • The author then proceeded to fix all identified violations of this check across various Java modules.
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.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@stankiewicz
Copy link
Contributor Author

Run Java_GCP_IO_Direct PreCommit

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