Skip to content

Conversation

@blakeli0
Copy link
Contributor

Add protobuf 3.x compatibility tests with a third party library tensorflow in showcase module.

Tensorflow depends on protobuf-java
v3.21.9
gen code and runtime. This proves that client libraries with 4.33 runtime and gen code are compatible with a third party library that contains 3.x gen code and runtime.

…y tensorflow. (#4015)

Add protobuf 3.x compatibility tests with a third party library
tensorflow in showcase module.

Tensorflow depends on [protobuf-java
v3.21.9](https://github.com/tensorflow/java/blob/cbf942051d55291ba9bdb019b2f207f013889bba/tensorflow-core/pom.xml#L45)
gen code and runtime. This proves that client libraries with 4.33
runtime and gen code are compatible with a third party library that
contains 3.x gen code and runtime.

---------

Co-authored-by: cloud-java-bot <cloud-java-bot@google.com>
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Jan 22, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @blakeli0, 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 introduces a new set of integration tests designed to validate the backward compatibility of the project's current Protobuf 4.x implementation with older Protobuf 3.x versions. By integrating TensorFlow, which uses Protobuf 3.x, the changes demonstrate that client libraries built with Protobuf 4.x can seamlessly interact with systems and data structures relying on Protobuf 3.x, ensuring broader ecosystem compatibility.

Highlights

  • Protobuf 3.x Compatibility Testing: Added new integration tests to verify compatibility between the current Protobuf 4.x runtime/generated code and third-party libraries (specifically TensorFlow) that rely on Protobuf 3.x.
  • TensorFlow Dependency: Introduced the tensorflow-core-platform dependency (version 1.1.0) in java-showcase/gapic-showcase/pom.xml with test scope to facilitate the compatibility tests.
  • New Maven Profile for Compatibility Tests: Created a new Maven profile named protobuf3 in java-showcase/gapic-showcase/pom.xml to specifically include and run the ITProtobuf3Compatibility.java test, while excluding other logging-related tests.
  • Exclusion from Default Builds: Configured the main java-showcase/pom.xml to exclude the new ITProtobuf3Compatibility.java test from default Maven builds, ensuring it only runs when the protobuf3 profile is explicitly activated.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/ci.yaml
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.

@blakeli0 blakeli0 assigned JoeWang1127 and unassigned JoeWang1127 Jan 22, 2026
@blakeli0 blakeli0 requested a review from JoeWang1127 January 22, 2026 23:18
Copy link
Contributor

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

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 adds a new compatibility test to ensure that client libraries using Protobuf 4.x are compatible with third-party libraries, like TensorFlow, that depend on Protobuf 3.x. The changes include adding the TensorFlow dependency, creating a new test case, and configuring Maven profiles to run this test in isolation. The implementation is sound, but I have one suggestion to improve the robustness of the new test code by handling potential exceptions more gracefully.

Comment on lines +57 to +66
private static Integer getValueFromGraphDefByName(GraphDef graphDef, String name1) {
return graphDef.getNodeList().stream()
.filter(nodeDef -> nodeDef.getName().equals(name1))
.findFirst()
.get()
.getAttrOrThrow("value")
.getTensor()
.getIntValList()
.get(0);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation of getValueFromGraphDefByName uses .get() on an Optional and .get(0) on a List without checking for presence or emptiness. This can lead to NoSuchElementException or IndexOutOfBoundsException if the expected node or value is not found, which can make debugging test failures difficult. Using orElseThrow with a descriptive message would provide more informative error messages.

Additionally, the parameter name name1 is a bit specific for a general-purpose helper method. Renaming it to name would improve clarity.

I've suggested a change that addresses both points, making the method more robust and readable.

  private static Integer getValueFromGraphDefByName(GraphDef graphDef, String name) {
    return graphDef.getNodeList().stream()
        .filter(nodeDef -> nodeDef.getName().equals(name))
        .findFirst()
        .orElseThrow(() -> new AssertionError("Node not found: " + name))
        .getAttrOrThrow("value")
        .getTensor()
        .getIntValList()
        .stream()
        .findFirst()
        .orElseThrow(() -> new AssertionError("Node has no int value: " + name));
  }

@sonarqubecloud
Copy link

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@blakeli0 blakeli0 merged commit 28cc591 into main Jan 23, 2026
59 of 61 checks passed
@blakeli0 blakeli0 deleted the add-tensorflow branch January 23, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants