Skip to content

Update to Protobuf 4.x #11015

Open
Open

Description

@neeme-praks-sympower

Edit by @ejona86: Protobuf has resolved the incompatibility with protobuf-java 4.x. For current status, see my two comments starting at #11015 (comment)

Edit by @ejona86: Protobuf 4.33 supports all 3.x generated code, so most things preventing people from upgrading should be resolved. Even though it supports 3.x generated code, that is just to make it easier for you to upgrade to the newer codegen; 5.x will probably still be dropping 3.x codegen support. #11015 (comment)


Is your feature request related to a problem?

I would like to use the latest released version of Protobuf (4.26.0) but I cannot as gRPC is still using the old version.

Describe the solution you'd like

Update Protobuf dependency and make it work with the new version.

Describe alternatives you've considered

I hoped that the update would be easy (just a version bump) so I tried doing it myself but it resulted in a compilation failure so I'll leave it to you to figure it out.

The failure:

> Task :grpc-protobuf:compileJava FAILED
grpc-java/protobuf/src/main/java/io/grpc/protobuf/StatusProto.java:38: error: cannot access GeneratedMessageV3
          ProtoLiteUtils.metadataMarshaller(com.google.rpc.Status.getDefaultInstance()));
                                                                 ^
  class file for com.google.protobuf.GeneratedMessageV3 not found
grpc-java/protobuf/src/main/java/io/grpc/protobuf/StatusProto.java:171: error: cannot access Builder
        .setCode(status.getCode().value());
        ^
  class file for com.google.protobuf.GeneratedMessageV3$Builder not found
2 errors

Activity

  1. ganadist commented on Mar 15, 2024

    @ganadist

    https://protobuf.dev/news/2023-12-05

    Also, I'm wondering how this protobuf changes will affect

    • gRPC public API changes
    • Compatibility with artifacts which were generated by old protobuf/gRPC compilers.
  2. added
    gRPC 2.0
    on Mar 15, 2024
  3. ejona86 commented on Mar 15, 2024

    @ejona86
    Member

    The protobuf breakage is pretty serious and goes against wisdom like https://jlbp.dev/JLBP-7 . I don't see how the community can absorb it. googleapis libraries are hit even harder than we are, so I think we'd wait until they have an idea how to deal with this (otherwise they couldn't upgrade to newer grpc versions). I don't expect that to be too big of a problem for the community, as I think most protobuf-using projects will be in shock.

    I'm in discussions with others, but I'd expect the process to figure this out to take months.

  4. augi commented on Mar 17, 2024

    @augi

    After updating to Protobuf 4.26.0, we observe this issue:

    java.lang.NoClassDefFoundError: com/google/protobuf/GeneratedMessageV3
    	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
    	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
    	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
    	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    	at io.grpc.health.v1.HealthGrpc.getCheckMethod(HealthGrpc.java:38)
    	at io.grpc.health.v1.HealthGrpc.getServiceDescriptor(HealthGrpc.java:413)
    	at io.grpc.health.v1.HealthGrpc.bindService(HealthGrpc.java:350)
    	at io.grpc.health.v1.HealthGrpc$HealthImplBase.bindService(HealthGrpc.java:169)
    

    The announcement of the Protobuf release contains this: [Java] The base class for generated messages will be GeneratedMessage, not GeneratedMessageV3.

    So I guess this has to be adjusted.

  5. changed the title [-]Update to Protobuf 4.26.0[/-] [+]Update to Protobuf 4.x[/+] on Mar 20, 2024
  6. added this to the Next milestone on Mar 20, 2024
  7. suztomo commented on Mar 22, 2024

    @suztomo
    Contributor

    @neeme-praks-sympower Does any library or dependency require you to upgrade Protobuf runtime version to 4.x?

  8. be-hase commented on Mar 22, 2024

    @be-hase

    It seems that proto-google-common-protos, which grpc-protobuf depends on, is not yet ver4 compliant.
    https://github.com/googleapis/sdk-platform-java/tree/main/java-common-protos

  9. krickert commented on Mar 30, 2024

    @krickert

    Why couldn't grpc just bring back generated message v3? The classes appear almost identical, I suppose it can just extend it?

    I tried that myself - it somewhat worked. I got past the generated message v3 error, but I was getting serializaiton errors everywhere. I think they may have changed the serializaiton spec too?

    Anyway, I'm looking forward to this fix. I might try this again today.

  10. neeme-praks-sympower commented on Apr 1, 2024

    @neeme-praks-sympower
    Author

    @neeme-praks-sympower Does any library or dependency require you to upgrade Protobuf runtime version to 4.x?

    No. We just try to keep our dependencies up-to-date.

  11. 34 remaining items

  12. ejona86 commented on Jan 15, 2025

    @ejona86
    Member

    @infa-kvaibhav, makeExtensionsImmutable() is from ~21.7 and older which is too-old of generated code. The library needs to be rebuilt with protoc 25 to support both 3.x and 4.x. See protocolbuffers/protobuf#17247 (comment)

  13. abasu0713 commented on Jul 6, 2025

    @abasu0713

    I have spent over 4 days trying this out to no avail. And it's a bit frustrating to be honest. Pardon my candor.
    I have multiple server implementations.. Some written in Dart, some in Go, some in Python.. I generate stubs myself. all using latest protoc version 4.29.3. I use multiple clients as well. Some written in Flutter and some in JS Frameworks. They all work seamlessly even with grpc-web with json transcoding for rest over Envoy.
    I need to write a Java based Events Listener SPI for Keycloak where I am using grpc java client to talk to dart and go servers as a post auth hook on keycloak. I have not been able to get it working. I keep getting the following error.

    2025-07-05 22:14:36,401 SEVERE [SignupEventListenerProvider] (executor-thread-3) Failed to create user using custom SPI: UNKNOWN: Channel Pipeline: [ProtocolNegotiators$PlaintextHandler#0, WriteBufferingAndExceptionHandler#0, DefaultChannelPipeline$TailContext#0]

    My Maven dependencies look like the following:

    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.example.auth</groupId>
      <artifactId>signup-spi</artifactId>
      <version>1.0.5</version>
      <packaging>jar</packaging>
      <name>custom-signup-spi</name>
    
      <build>
        <finalName>signup-spi</finalName> <!-- optional clean output name -->
        <extensions>
          <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.7.1</version>
          </extension>
        </extensions>
        <plugins>
          <!-- Protobuf Codegen -->
          <plugin>
            <groupId>org.xolstice.maven.plugins</groupId>
            <artifactId>protobuf-maven-plugin</artifactId>
            <version>0.6.1</version>
            <configuration>
              <protocArtifact>com.google.protobuf:protoc:3.25.5:exe:${os.detected.classifier}</protocArtifact>
              <pluginId>grpc-java</pluginId>
              <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.73.0:exe:${os.detected.classifier}</pluginArtifact>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>compile</goal>
                  <goal>compile-custom</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
    
          <!-- Shade Plugin for Guava conflict resolution -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.5.1</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
                <configuration>
                  <createDependencyReducedPom>false</createDependencyReducedPom>
                  <relocations>
                    <relocation>
                      <pattern>com.google.common</pattern>
                      <shadedPattern>com.biterush.shaded.guava</shadedPattern>
                    </relocation>
                  </relocations>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    
      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-parent</artifactId>
            <version>26.2.5</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>
      </dependencyManagement>
    
      <dependencies>
        <!-- Keycloak SPI Dependencies -->
        <dependency>
          <groupId>org.keycloak</groupId>
          <artifactId>keycloak-server-spi</artifactId>
          <version>26.2.5</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.keycloak</groupId>
          <artifactId>keycloak-server-spi-private</artifactId>
          <version>26.2.5</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.keycloak</groupId>
          <artifactId>keycloak-core</artifactId>
          <version>26.2.5</version>
        </dependency>
    
        <!-- gRPC Dependencies -->
        <dependency>
          <groupId>io.grpc</groupId>
          <artifactId>grpc-netty-shaded</artifactId>
          <version>1.63.0</version>
        </dependency>
        <dependency>
          <groupId>io.grpc</groupId>
          <artifactId>grpc-protobuf</artifactId>
          <version>1.63.0</version>
        </dependency>
        <dependency>
          <groupId>io.grpc</groupId>
          <artifactId>grpc-stub</artifactId>
          <version>1.63.0</version>
        </dependency>
    
        <!-- Protobuf Runtime -->
        <dependency>
          <groupId>com.google.protobuf</groupId>
          <artifactId>protobuf-java</artifactId>
          <version>3.25.3</version> <!-- doesn't work with 4.29.3 either -->
        </dependency>
    
        <!-- Guava (for gRPC internals) -->
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>32.1.3-jre</version>
        </dependency>
    
        <!-- Java 17 compatibility (Keycloak requirement) -->
        <dependency>
          <groupId>org.apache.tomcat</groupId>
          <artifactId>annotations-api</artifactId>
          <version>6.0.53</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </project>

    Can someone give me some idea what is going on?

  14. ascopes commented on Jul 6, 2025

    @ascopes

    @abasu0713 this probably isn't the answer but just if you were not aware, the newest version of protoc and protobuf-java is 4.31.1; I've got that working with grpc-java 1.73.0 in basic integration tests (nothing as complex as what you need though!) so it may be worth trying with that as well. I doubt it will fix your issue but it rules that out at the very least.

  15. h-vetinari commented on Jul 6, 2025

    @h-vetinari

    I generate stubs myself. all using latest protoc version 4.29.3.

    Just to note that latest right now is v31.1 (the baseline protobuf version; the leading major versions are different per language, i.e. 4.31.1 on the java side)

    Edit: sorry, I hadn't seen that there was another comment to the same effect before I wrote my own.

  16. ejona86 commented on Jul 7, 2025

    @ejona86
    Member

    @abasu0713, I don't see anything about your report that makes it seem related to protobuf. Please open a new issue to discuss instead of doing it here.

    Is there no more log information, like an exception stack trace or the like? Did you write the code for SignupEventListenerProvider?

  17. ejona86 commented on Aug 13, 2025

    @ejona86
    Member

    FYI: Protobuf 32 is adding support for older generated code. See the rc2 release notes:
    https://github.com/protocolbuffers/protobuf/releases/tag/v32.0-rc2

  18. krickert commented on Aug 16, 2025

    @krickert

    Wanted to add to this thread.. I just added 4.x to my project and enforced it and it worked on the first shot!!! It's totally working and rockin'.. Been a long time comin.. I still have a lot of tests to do so YMMV

  19. ejona86 commented on Oct 20, 2025

    @ejona86
    Member

    Protobuf 4.33.0 supports all protobuf 3.x generated code: https://github.com/protocolbuffers/protobuf/releases/tag/v33.0

    Do read the release notes, as it mentions how it handles vulnerabilities that exist in older generated code. Note that you still should not use GeneratedMessage or GeneratedMessageV3 in your code; use Message instead.

    I'm discussing with others when to upgrade. It seems it might happen soon. The largest source of remaining breakage is probably people using GeneratedMessageV3.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions