Skip to content

[bazel] fix running google formatter with too many files - #17065

Merged
titusfortner merged 1 commit into
SeleniumHQ:trunkfrom
asolntsev:fix/running-google-formatter-with-too-many-files
Feb 9, 2026
Merged

titusfortner merged 1 commit into
SeleniumHQ:trunkfrom
asolntsev:fix/running-google-formatter-with-too-many-files

Conversation

@asolntsev

Copy link
Copy Markdown
Contributor

Current formatting script fails on GitHub Actions with "too many arguments" error:

INFO: Running command line: bazel-bin/scripts/google-java-format --replace /home/runner/work/selenium/selenium/java/src/dev/selenium/tools/javadoc/JavadocJarMaker.java /home/runner/work/selenium/selenium/java/src/dev/selenium/tools/modules/ModuleGenerator.java
...
...
/home/runner/work/selenium/selenium/java/test/org/openqa/selenium/testing/drivers/TestInternetExplorerSupplier.java /home/runner/work/selenium/selenium/java/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java /home/runner/work/selenium/selenium/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java
FATAL: execv of '/bin/bash' failed: (error: 7): Argument list too long

🔗 Related Issues

See for example
https://github.com/SeleniumHQ/selenium/actions/runs/21830997104/job/62992987104?pr=17064

💥 What does this PR do?

Passes files list via argfile, not as an array of arguments.

🔧 Implementation Notes

Before:

bazel run //scripts:google-java-format -- --replace JavadocJarMaker.java ModuleGenerator.java ... VirtualAuthenticatorTest.java

After:

bazel run //scripts:google-java-format -- --replace @/var/folders/z1/35579q8s5cvcnmb6cnp0xpjw0000gn/T/google-java-format-files20260209-81962-mdwsdj

🔄 Types of changes

  • Bug fix (backwards compatible)

Current formatting script fails on GitHub Actions with "too many arguments" error:

```
INFO: Running command line: bazel-bin/scripts/google-java-format --replace /home/runner/work/selenium/selenium/java/src/dev/selenium/tools/javadoc/JavadocJarMaker.java /home/runner/work/selenium/selenium/java/src/dev/selenium/tools/modules/ModuleGenerator.java
...
...
/home/runner/work/selenium/selenium/java/test/org/openqa/selenium/testing/drivers/TestInternetExplorerSupplier.java /home/runner/work/selenium/selenium/java/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java /home/runner/work/selenium/selenium/java/test/org/openqa/selenium/virtualauthenticator/VirtualAuthenticatorTest.java
FATAL: execv of '/bin/bash' failed: (error: 7): Argument list too long
```

See for example
https://github.com/SeleniumHQ/selenium/actions/runs/21830997104/job/62992987104?pr=17064
@asolntsev asolntsev added this to the 4.41.0 milestone Feb 9, 2026
@asolntsev asolntsev self-assigned this Feb 9, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Type

Bug fix


Description

  • Fix "Argument list too long" error in Google Java formatter

  • Pass file list via argfile instead of command-line arguments

  • Use temporary file to store Java file paths for formatter

  • Prevents GitHub Actions CI failures with large file counts


File Walkthrough

Relevant files
Bug fix
java.rake
Use argfile for Google Java formatter file list                   

rake_tasks/java.rake

  • Modified format task to use temporary file for file list
  • Changed from passing files as direct arguments to using @argfile
    syntax
  • Wrapped file writing in Tempfile.create block for proper cleanup
  • Maintains same functionality while avoiding shell argument limit
+7/-2     

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
⚪
Argfile injection

Description: Potential argument injection via argfile: writing unescaped file paths into the @#{f.path}
argfile means a maliciously crafted .java filename containing newlines (or other
argfile-parsed separators) could inject additional unintended arguments into
google-java-format when it parses the argfile.
java.rake [399-405]

Referred Code
Tempfile.create('google-java-format-files') do |f|
  java_files.each { |file| f.puts(file) }
  f.flush

  args = ['--', '--replace', "@#{f.path}"]
  Bazel.execute('run', args, '//scripts:google-java-format')
end
Ticket Compliance
⚪
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
⚪
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

⚪
Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing failure context: The new Tempfile.create/Bazel.execute flow has no explicit handling to add actionable
context if writing the argfile or running the formatter fails (it may rely on
Bazel.execute raising/logging elsewhere).

Referred Code
Tempfile.create('google-java-format-files') do |f|
  java_files.each { |file| f.puts(file) }
  f.flush

  args = ['--', '--replace', "@#{f.path}"]
  Bazel.execute('run', args, '//scripts:google-java-format')
end

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Abort on formatting failure

Check the return value of Bazel.execute and fail the Rake task if the command is
unsuccessful to prevent silent failures.

rake_tasks/java.rake [404]

-Bazel.execute('run', args, '//scripts:google-java-format')
+success = Bazel.execute('run', args, '//scripts:google-java-format')
+fail 'google-java-format failed' unless success
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: This is a critical improvement for CI/CD integrity, as it ensures the Rake task will fail if the code formatting command fails, preventing silent errors from going unnoticed.

Medium
Possible issue
Close temp file before execution

Add f.close after f.flush and before Bazel.execute to prevent potential
file-locking errors on certain operating systems like Windows.

rake_tasks/java.rake [401-404]

 f.flush
+f.close
 
 args = ['--', '--replace', "@#{f.path}"]
 Bazel.execute('run', args, '//scripts:google-java-format')
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This is a valid suggestion that improves the robustness of the script by explicitly closing the tempfile before an external process reads it, which can prevent file-locking issues, particularly on Windows.

Medium
  • More

@asolntsev asolntsev changed the title fix running google formatter with too many files [java] fix running google formatter with too many files Feb 9, 2026
@asolntsev asolntsev changed the title [java] fix running google formatter with too many files [bazel] fix running google formatter with too many files Feb 9, 2026
@selenium-ci selenium-ci added the B-build Includes scripting, bazel and CI integrations label Feb 9, 2026

@titusfortner titusfortner 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.

Thank you! Was trying to figure out how to make this work without outputting everything to console.

@titusfortner
titusfortner merged commit 57324e1 into SeleniumHQ:trunk Feb 9, 2026
21 of 26 checks passed
@asolntsev
asolntsev deleted the fix/running-google-formatter-with-too-many-files branch February 9, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations Review effort 2/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants