scalapb/ScalaPB

java.lang.IllegalAccessError: tried to access method 'com.google.protobuf.LazyStringArrayList'

Opened this issue · 10 comments

Hello!
I am using scalapb in my repository and now have to use some library with dependency on protobuf-java:3.22.5
Now I am on protobuf-java:3.19.2 and the code fails with:

tried to access method 'com.google.protobuf.LazyStringArrayList com.google.protobuf.LazyStringArrayList.emptyList()

This issue says it should work with protobuf-java > 3.22.0
This comment says protobuf 3.21 will be here only by next major release of ScalaPB (0.12)
But what about 3.22?

Maybe you can give me some advices or workarounds how to use scalaPB and up-to-date protobuf together?

I think that ScalaPB should work with recent versions of protobuf-java (such as 3.22.x). Can you share more information about your project? Are you generating Scala and Java code? Are you setting PB.protocVersion to 3.22.5? What code path leads to the exception you are seeing? Can you share a minimal project that reproduces this problem?

Oh so this is just my misunderstanding. I thought I just will not work.
Yes, I have java + scala repo and generating both scala / java classes from proto. So it is safe to use protoc + protobuf-java with version (3.22.5) > currently hardcoded in ScalaPB (3.19.6), is it?

I haven't tested this specific configuration, so it may or may not work. However, generally it should be ok to use a newer protobuf-java and protoc than the one used with ScalaPB. Please test that and report here you see any issues.

It looks like protobuf v3.22.0 introduces incompatible change in DescriptorProtos.FieldOptions.Builder setExtension method: now it is inherited from com.google.protobuf.GeneratedMessageV3.ExtendableBuilder
In 3.19.6 it was presented in DescriptorProtos.FieldOptions.Builder itself

I tried to compile scala proto librarary with current scalapb and protobuf-java + protoc 3.22.5 and get such error:
--scala_out: java.lang.NoSuchMethodError: 'com.google.protobuf.DescriptorProtos$FieldOptions$Builder com.google.protobuf.DescriptorProtos$FieldOptions$Builder.setExtension(com.google.protobuf.GeneratedMessage$GeneratedExtension, java.lang.Object)' at scalapb.compiler.ProtobufGenerator.updateField$1(ProtobufGenerator.scala:1471)

Then I upgrade protobuf (and protoc) in scalapb repo to 3.22.5 and just recompiled compilerplugin. It fixes the problem.

Would you mind to upgrade protobuf to 3.22.5?

@kusaeva can you provide a minimal project that demonstrates the problem? I prefer to refrain from a releasing a 0.12.0 if not necessary.

sure, here it is https://github.com/kusaeva/scalapb-protobuf-22.5
Running sbt compile fails with protobuf 3.22.5 but works with 3.21.7

Thanks for sending this. It looks like the use of dependencyOverrides affects the protobuf version used at compile time (!) and I wonder if this is an sbt bug. If you change dependencyOverrides to libraryDependencies then it works. Is there a reason for the usage of dependencyOverrides?

I used dependencyOverrides just for example. My real project built with bazel, where I have to use certain protobuf version (22.5). And I get the same error

Got it. I am planning of making a release with a more recent version of protobuf. However, since the problem occurs at compile time, it looks like the generator isn't running in isolation as I thought (we have a custom class loader that was meant to provide that). So upgrading can cause binary incompatibility for users who need the older version at compile time. While we do the new release, care to share a bazel reproduction of the issue? I am not sure how the class loading for the generator works there.

Sorry for late reply, I've added bazel build to the same repro repository: https://github.com/kusaeva/scalapb-protobuf-22.5
To see the error run: bazel build //:all