Skip to content

refactor(bigquery): simplify FieldValue.getBooleanValue() to avoid duplicate check - #15007

Open
lqiu96 wants to merge 1 commit into
googleapis:mainfrom
lqiu96:perf/bq-t1-07-fieldvalue-boolean-flyweights
Open

lqiu96 wants to merge 1 commit into
googleapis:mainfrom
lqiu96:perf/bq-t1-07-fieldvalue-boolean-flyweights

Conversation

@lqiu96

@lqiu96 lqiu96 commented Nov 13, 2026

Copy link
Copy Markdown
Member

Summary

Simplifies FieldValue.getBooleanValue() to check "true" and "false" once while preserving the existing IllegalStateException contract.

Previously, getBooleanValue() validated both literals with Preconditions.checkState(stringValue.equalsIgnoreCase("true") || stringValue.equalsIgnoreCase("false"), ...) and then called Boolean.parseBoolean(stringValue) (which performs "true".equalsIgnoreCase(stringValue) a second time, since Boolean.parseBoolean on its own would return false for invalid strings).

Changes

  • FieldValue:
    • Check "true".equalsIgnoreCase(stringValue) and "false".equalsIgnoreCase(stringValue) directly in getBooleanValue() and throw IllegalStateException if neither matches.
    • Add an inline comment explaining why explicit validation is used instead of delegating directly to Boolean.parseBoolean.
    • Remove the now-unused Preconditions.checkState import.
  • FieldValueTest:
    • Added testGetBooleanValue covering "true", "false", mixed case, and invalid strings throwing IllegalStateException.

Verification

  • mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=FieldValueTest (7 passed)
  • mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=FieldValueListTest (5 passed)

@lqiu96
lqiu96 requested review from a team as code owners November 13, 2026 21:43

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the getBooleanValue method in FieldValue.java to explicitly validate and parse boolean strings ("true" and "false" case-insensitively) and throw an IllegalStateException for invalid inputs, replacing the previous usage of Guava's checkState and Boolean.parseBoolean. Additionally, corresponding unit tests have been added in FieldValueTest.java to verify this behavior. There are no review comments, and I have no feedback to provide.

@lqiu96
lqiu96 enabled auto-merge (squash) November 13, 2026 22:10

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant