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 exception, caused by dependency conflict with Guava in truth/extensions/liteproto #473

Closed
LeoAugust19 opened this issue Jul 11, 2018 · 8 comments
Milestone

Comments

@LeoAugust19
Copy link

LeoAugust19 commented Jul 11, 2018

Hi, dependency conlict issue exists in truth/extensions/liteproto. As shown in the following dependency tree, this project directly depends on com.google.guava:guava:jar:23.6, and transitively depends on com.google.guava:guava:jar:25.1, based on Maven's loading mechanism, the old version wins the newer one.

Dependency tree:
com.google.truth.extensions:truth-liteproto-extension:jar:0.41
+- com.google.truth:truth:jar:0.41:compile
| +- (com.google.guava:guava:jar:25.1-android:compile - omitted for conflict with 23.6-android)
+- com.google.guava:guava:jar:23.6-android:compile

However, method com.google.common.base.Strings.lenientFormat(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String is referenced by the host project and only defined in guava:jar:25.1, which causes the java.lang.NoSuchMethodError exception.

When executing the following test case, we got the stack trace:

Test case:

LiteProtoTruth.assertThat(UnknownFieldSet.getDefaultInstance()).isEqualTo(new Object());

Stack trace:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Strings.lenientFormat(Ljava/lang/String;

[Ljava/lang/Object;)Ljava/lang/String;
at com.google.common.truth.Subject.failWithRawMessage(Subject.java:1043)
at com.google.common.truth.extensions.proto.LiteProtoSubject.isEqualTo(LiteProtoSubject.java:106)
at com.google.common.truth.extensions.proto.Test.main(Test.java:11)

The solution is to update com.google.guava:guava:jar:23.6 to 25.1 to make the version consistent.

Hope this report can help you. Thanks! ^_^

@cpovirk
Copy link
Member

cpovirk commented Jul 11, 2018

Thanks and sorry. I will get together a fix.

@cpovirk
Copy link
Member

cpovirk commented Jul 11, 2018

I got to wondering how this passed our tests, and:

<maven.test.skip>true</maven.test.skip>

@cpovirk cpovirk added this to the 0.42 milestone Jul 12, 2018
@cpovirk
Copy link
Member

cpovirk commented Jul 12, 2018

Fix released in Truth 0.42.

@Nyeng
Copy link

Nyeng commented Aug 7, 2018

Not sure if this is the same thing, but I get the same error message from this:

 assertWithMessage("Strings are not equal")
            .that("asd")
            .isEqualTo("test");

java.lang.NoSuchMethodError: com.google.common.base.Strings.lenientFormat(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
When I change the test to pass the error doesn't happen.

@cpovirk
Copy link
Member

cpovirk commented Aug 7, 2018

That sounds like at least a similar problem. If you're using Truth 0.41, you can try upgrading to 0.42 and seeing if that helps. If not, you may need to manually force Maven (or whatever build system you're using) to pull in version 25.1 of Guava, typically with something like...

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>25.1-jre</version>
    </dependency>

It may be possible to detect potential such problems (where a newer version of a dependency is overridden by a newer one) by using requireUpperBoundDeps.

@cpovirk
Copy link
Member

cpovirk commented Aug 9, 2018

From my perspective, either one is sufficient.

I am particularly interested in the static analysis, though: It seems like it would have the potential to identify more problems more easily. That could include problems from combining two different libraries that request different versions of a common dependency. If you ever have a tool that we can run continually on Truth and other Google projects, or if you have other information to share, I'd be happy to hear about it :)

cpovirk added a commit that referenced this issue Aug 15, 2018
…ava to 26.0.

The Guava update doesn't solve any dependency conflicts, but, as I've noted in a comment in pom.xml, it helps requireUpperBoundDeps actually work. (But other such problems might still go undetected.)

requireUpperBoundDeps has to exclude Guava, so it wouldn't have caught the problem in #473, but dependencyConvergence would have.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=208710143
ronshapiro pushed a commit that referenced this issue Aug 15, 2018
…ava to 26.0.

The Guava update doesn't solve any dependency conflicts, but, as I've noted in a comment in pom.xml, it helps requireUpperBoundDeps actually work. (But other such problems might still go undetected.)

requireUpperBoundDeps has to exclude Guava, so it wouldn't have caught the problem in #473, but dependencyConvergence would have.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=208710143
@ronshapiro ronshapiro mentioned this issue Aug 15, 2018
@LeoAugust19
Copy link
Author

Hi, @cpovirk, If available, could you please send me an Email ([email protected]), because I didn't find your contact information. We developed a tool that can automatically detect the dependency conflict (DC) issue using static analysis. We hope that you can try out our tool and give us some suggestions to improve it. We look forward to cooperating with you to perfect this tool and using it to run continually on Google projects and other open source community projects. After all, ensuring the projects’ long-term health and improve their maintainability is our common aspiration.

@cpovirk
Copy link
Member

cpovirk commented Jan 30, 2019

Thanks! I was OOO for a few months, and now I'm playing catchup, but I've pointed some teammates to this message. They'll have a better idea of whether they can be in touch anytime soon.

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

3 participants