Skip to content

[ErrorProne] Enable MutablePublicArray Error Prone Check#37761

Merged
Abacn merged 2 commits intoapache:masterfrom
stankiewicz:error_prone_MutablePublicArray
Mar 4, 2026
Merged

[ErrorProne] Enable MutablePublicArray Error Prone Check#37761
Abacn merged 2 commits intoapache:masterfrom
stankiewicz:error_prone_MutablePublicArray

Conversation

@stankiewicz
Copy link
Contributor

This PR removes MutablePublicArray from the disabledChecks list in Error Prone (within BeamModulePlugin.groovy) and resolves the warnings throughout the codebase.
The MutablePublicArray rule enforces that public static final arrays are not exposed as public constants, because arrays in Java are fundamentally mutable. Exposing arrays allows clients to dangerously modify individual elements, thereby altering the constant state.


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 enhances code safety by enforcing the MutablePublicArray Error Prone check. This prevents the exposure of mutable arrays as public constants, which could lead to unintended state changes. The changes involve updating the build configuration to enable the check and refactoring existing code to comply with this new standard, primarily by adjusting the visibility of static final arrays and modifying their usage patterns.

Highlights

  • Error Prone Check Enabled: The MutablePublicArray Error Prone check has been enabled by removing it from the disabled checks list in BeamModulePlugin.groovy.
  • Array Visibility Refactoring: Several public static final array declarations in TestUtils.java were changed to private static final to prevent external modification, aligning with the MutablePublicArray rule.
  • Updated Array Usage: References to the previously public arrays in various test files (e.g., TextIOReadTest, TextIOWriteTest, CreateTest, FlattenTest, ContextualTextIOTest) were updated to use the corresponding List.toArray() method, ensuring immutability at the public interface.

🧠 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 'MutablePublicArray' from the list of disabled Error Prone checks.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/TestUtils.java
    • Changed 'NO_LINES_ARRAY', 'LINES_ARRAY', 'LINES2_ARRAY', 'NO_INTS_ARRAY', and 'INTS_ARRAY' from public to private.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOReadTest.java
    • Updated static imports from 'LINES_ARRAY' and 'NO_LINES_ARRAY' to 'LINES' and 'NO_LINES' respectively.
    • Modified calls to 'runTestRead' to pass 'LINES.toArray(new String[0])' and 'NO_LINES.toArray(new String[0])' instead of direct array references.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/io/TextIOWriteTest.java
    • Updated static imports from 'LINES2_ARRAY', 'LINES_ARRAY', and 'NO_LINES_ARRAY' to 'LINES2', 'LINES', and 'NO_LINES' respectively.
    • Modified calls to 'runTestWrite' and 'Create.of' to pass 'List.toArray()' results instead of direct array references.
    • Updated the initialization of 'drunkElems' to use 'LINES2.toArray(new String[0]).length'.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/CreateTest.java
    • Updated static imports for 'LINES_ARRAY' and 'NO_LINES_ARRAY' to 'LINES' and 'NO_LINES' respectively.
    • Modified 'PAssert.that(output).containsInAnyOrder' calls to use 'LINES.toArray(new String[0])' and 'NO_LINES.toArray(new String[0])'.
  • sdks/java/core/src/test/java/org/apache/beam/sdk/transforms/FlattenTest.java
    • Updated static imports for 'LINES_ARRAY' and 'NO_LINES_ARRAY' to 'LINES' and 'NO_LINES' respectively.
    • Modified 'PAssert.that(output).containsInAnyOrder' calls to use 'LINES.toArray(new String[0])' and 'NO_LINES.toArray(new String[0])'.
  • sdks/java/io/contextualtextio/src/test/java/org/apache/beam/sdk/io/contextualtextio/ContextualTextIOTest.java
    • Updated static imports from 'LINES_ARRAY' and 'NO_LINES_ARRAY' to 'LINES' and 'NO_LINES' respectively.
    • Modified calls to 'runTestRead' and 'runTestReadLineNumsAndFileName' to pass 'List.toArray()' results instead of direct array references.
Activity
  • The pull request was created by stankiewicz.
  • No human activity (comments, reviews, or progress updates) has been recorded on this pull request yet.
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

Assigning reviewers:

R: @chamikaramj for label java.
R: @Abacn for label build.

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

Copy link
Contributor

@Abacn Abacn left a comment

Choose a reason for hiding this comment

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

Thank you!

@Abacn Abacn merged commit 7ba0efd into apache:master Mar 4, 2026
26 of 27 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.

2 participants