Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kusaeva opened this issue Mar 5, 2024 · 10 comments

Comments

@kusaeva
Copy link

kusaeva commented Mar 5, 2024

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?

@thesamet
Copy link
Contributor

thesamet commented Mar 5, 2024

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?

@kusaeva
Copy link
Author

kusaeva commented Mar 7, 2024

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?

@thesamet
Copy link
Contributor

thesamet commented Mar 7, 2024

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.

@kusaeva
Copy link
Author

kusaeva commented Mar 12, 2024

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?

@thesamet
Copy link
Contributor

@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.

@kusaeva
Copy link
Author

kusaeva commented Mar 13, 2024

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

@thesamet
Copy link
Contributor

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?

@kusaeva
Copy link
Author

kusaeva commented Mar 14, 2024

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

@thesamet
Copy link
Contributor

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.

@kusaeva
Copy link
Author

kusaeva commented Mar 24, 2024

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

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

No branches or pull requests

2 participants