Skip to content

fix(bigquery): [B-5] fix self-assignment and wrong-getter bugs in domain models - #29

Open
lqiu96 wants to merge 1 commit into
mainfrom
fix/bq-b5-domain-model-bugs
Open

lqiu96 wants to merge 1 commit into
mainfrom
fix/bq-b5-domain-model-bugs

Conversation

@lqiu96

@lqiu96 lqiu96 commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Summary & Bottleneck

Several domain model classes in google-cloud-bigquery contain self-assignment, wrong-getter, and switch fall-through bugs discovered during the codebase audit:

  1. IndexUnusedReason.toPb() self-assignment:
    • In java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/IndexUnusedReason.java, toPb() calls indexUnusedReason.setIndexName(indexUnusedReason.getIndexName()), indexUnusedReason.setCode(indexUnusedReason.getCode()), and indexUnusedReason.setMessage(indexUnusedReason.getMessage()) on the newly allocated empty protobuf instance instead of reading getIndexName(), getCode(), and getMessage() from this.
  2. JobStatistics.Builder(JobStatistics) uninitialized field check:
    • In java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java, Builder(com.google.api.services.bigquery.model.JobStatistics statisticsPb) checks if (reservationUsage != null) (which is always null on a newly constructed Builder) instead of if (statisticsPb.getReservationUsage() != null), causing getReservationUsage() to always return null after fromPb.
  3. ExternalTableDefinition.fromExternalDataConfiguration wrong getter:
    • In java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java, fromExternalDataConfiguration calls builder.setTimestampFormat(externalDataConfiguration.getTimeFormat()) instead of externalDataConfiguration.getTimestampFormat().
  4. QueryParameterValue duplicate String.class branches and case JSON: fall-through:
    • In java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java, classToType contains two unreachable duplicate else if (String.class.isAssignableFrom(type)) branches, and valueToStringOrNull is missing a break statement at the end of case JSON:, allowing non-JSON PeriodDuration values to fall through into case INTERVAL:.

Changes

  • java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/IndexUnusedReason.java:
    • Pass getIndexName(), getCode(), and getMessage() to the protobuf setters in toPb().
  • java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/JobStatistics.java:
    • Check if (statisticsPb.getReservationUsage() != null) in JobStatistics.Builder(statisticsPb).
  • java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java:
    • Pass externalDataConfiguration.getTimestampFormat() to builder.setTimestampFormat(...) in fromExternalDataConfiguration.
  • java-bigquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryParameterValue.java:
    • Remove the unreachable duplicate String.class branches in classToType and add the missing break statement in case JSON: of valueToStringOrNull.

Expected Impact

  • Restores lossless toPb() and fromPb() round-trip serialization for IndexUnusedReason, JobStatistics.getReservationUsage(), and ExternalTableDefinition.getTimestampFormat().
  • Prevents invalid PeriodDuration values from being silently accepted when constructing StandardSQLTypeName.JSON query parameters.

Verification

  • Added unit tests in java-bigquery/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java, ExternalTableDefinitionTest.java, and QueryParameterValueTest.java.
  • Ran mvn test -pl java-bigquery/google-cloud-bigquery -Dtest=JobStatisticsTest,ExternalTableDefinitionTest,QueryParameterValueTest (51 tests run, 0 failures).

@lqiu96
lqiu96 force-pushed the fix/bq-b5-domain-model-bugs branch 2 times, most recently from 987e603 to fc42699 Compare October 13, 2026 15:59
@lqiu96
lqiu96 force-pushed the fix/bq-b5-domain-model-bugs branch from fc42699 to aab8131 Compare October 13, 2026 17:16
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