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.NoSuchMethodError after protobuf version 3.3.0 #4521

Closed
zoukyle opened this issue Apr 17, 2018 · 13 comments
Closed

java.lang.NoSuchMethodError after protobuf version 3.3.0 #4521

zoukyle opened this issue Apr 17, 2018 · 13 comments
Assignees

Comments

@zoukyle
Copy link

zoukyle commented Apr 17, 2018

It works for version 3.3.0 and 3.2.0, but gives me the NoSuchMethod exception starting from version 3.4.0. Did anyone see this error before?

java.lang.NoSuchMethodError: com.google.protobuf.AbstractMessageLite$Builder.addAll(Ljava/lang/Iterable;Ljava/util/List;)V
at ai.deepmap.tracks.TrackInfoProtos$TrackInfo$Builder.addAllImageDirs(TrackInfoProtos.java:10947)
at ai.deepmap.servers.track_data_server.RpcTrackDataManagerStaticFilesTest.testGetTrackByNameSuccess(RpcTrackDataManagerStaticFilesTest.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at com.google.testing.junit.runner.internal.junit4.CancellableRequestFactory$CancellableRunner.run(CancellableRequestFactory.java:89)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:112)
at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:144)
at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:82)

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Apr 17, 2018

It's likely that you are using "optimize_for = LITE_RUNTIME" in your proto: that is not supported in Java any more and you can either remove it or switch to use Java Lite protoc plugin. See: #4314

@zoukyle
Copy link
Author

zoukyle commented Apr 17, 2018

I don't know if I'm using optimize_for = LITE_RUNTIME. How can I verify that?

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Apr 18, 2018

Can you check if the .proto file that's used to generate TrackInfoProtos.java contains:

option optimize_for = LITE_RUNTIME;

?

@zoukyle
Copy link
Author

zoukyle commented Apr 18, 2018

I see. None of my proto files contain the option optimize_for, so I don't think that's the root cause.

@zoukyle
Copy link
Author

zoukyle commented Apr 18, 2018

I found a work around:
The protobuf_3_5_0_20180413.tar.gz version is modified from the public released version because of addAll NoSuchFunction.
I had to use the addAll function from version 3.3 in file: java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Apr 18, 2018

Hmm, then you can double check you are depending on the right version of protobuf runtime? The method is still there as far as I can tell:
https://github.com/google/protobuf/blob/master/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java#L139

If you can provide a simple program that can reproduce the error, I can help take a look.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Apr 18, 2018

@zoukyle I don't understand your comment about protobuf_3_5_0_20180413.tar.gz. What is that?

@zoukyle
Copy link
Author

zoukyle commented Apr 18, 2018

@xfxyjwf I had to replace the addAll function in the file java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java (v3.5 version) with the same function in v3.3 version to make it work.
I can try to build a simple program to reproduce this. Will update soon.

@CageSama
Copy link

CageSama commented Jun 24, 2018

I get the same problem and I find that this is caused by jar conflict.
In a word, you're using wrong version of AbstractMessageLite$Builder at runtime.

In my case, my project depends both on protobuf-java-3.4.0 and protobuf-lite-3.0.1, both of them contain AbstractMessageLite$Builder.class, when compilng, protobuf-3.4.0.AbstractMessageLite$Builder is used, and when running, protobuf-lite-3.0.1.AbstractMessageLite$Builder is used
So I decompile these two class to see the difference using javap command,
in protobuf-lite-3.0.1.AbstractMessageLite$Builder.class:

protected static <T> void addAll(java.lang.Iterable<T>, java.util.Collection<? super T>);

in protobuf-3.4.0.AbstractMessageLite$Builder.class:

protected static <T> void addAll(java.lang.Iterable<T>, java.util.Collection<? super T>);
protected static <T> void addAll(java.lang.Iterable<T>, java.util.List<? super T>);

and in my Inquiry.class:

public inquiry.Inquiry$InquiryRequest$Builder addAllKeywordName(java.lang.Iterable<java.lang.String>);
    Code:
       0: aload_0
       1: invokespecial #92                 // Method ensureKeywordNameIsMutable:()V
       4: aload_1
       5: aload_0
       6: getfield      #18                 // Field keywordName_:Lcom/google/protobuf/LazyStringList;
       9: invokestatic  #124                // Method com/google/protobuf/AbstractMessageLite$Builder.addAll:(Ljava/lang/Iterable;Ljava/util/List;)V
      12: aload_0
      13: invokevirtual #77                 // Method onChanged:()V
      16: aload_0
      17: areturn

look at this line

9: invokestatic  #124                // Method com/google/protobuf/AbstractMessageLite$Builder.addAll:(Ljava/lang/Iterable;Ljava/util/List;)V

now u see how this error occurred.

As for your question, why 3.2.0 and 3.3.0 works fine, but 3.4.0 throws an error.
I decompile 3.3.0.AbstractMessageLite$Builder.class and 3.4.0.AbstractMessageLite$Builder.class.
In 3.3.0:

protected static <T> void addAll(java.lang.Iterable<T>, java.util.Collection<? super T>);

In 3.4.0.:

protected static <T> void addAll(java.lang.Iterable<T>, java.util.Collection<? super T>);
protected static <T> void addAll(java.lang.Iterable<T>, java.util.List<? super T>);

So it's the same as what I mentioned before.
Hope this can help :-)

@zoukyle
Copy link
Author

zoukyle commented Jun 25, 2018

@CageSama Thanks a lot for your explanation. It helped a lot.

@dheeru4java
Copy link

Hi,
I am also facing same issue when upgrade protobuf version from 3.3.1 to 3.4.0. like -

java.lang.NoSuchMethodError: 'void com.google.protobuf.AbstractMessageLite$Builder.addAll(java.lang.Iterable, java.util.List)'

Please suggest what is the resolution.

@perezd
Copy link
Contributor

perezd commented Jul 15, 2021

Is there anything preventing you from upgrading to the latest? We are up to 3.17 and this issue is from 2018.

@Hemanshi293
Copy link

Hello ,
I am seeing the same error and couldn't find any solution yet with protobuf-java version 3.11.0 and 3.16.1 as below-
java.lang.NoSuchMethodError: 'void com.google.protobuf.AbstractMessageLite$Builder.addAll(java.lang.Iterable, java.util.List)'

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

No branches or pull requests

6 participants