question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.expireAfterWrite(Ljava/time/Duration;)

See original GitHub issue

Caller: https://github.com/GoogleCloudDataproc/hadoop-connectors/blob/master/gcsio/src/main/java/com/google/cloud/hadoop/gcsio/GoogleCloudStorageImpl.java#L142

CacheBuilder.newBuilder()
          .expireAfterWrite(Duration.ofHours(1))

Callee: https://github.com/google/guava/blob/master/android/guava/src/com/google/common/cache/CacheBuilder.java#L654

public CacheBuilder<K, V> expireAfterWrite(long duration, TimeUnit unit) {
    checkState(
        expireAfterWriteNanos == UNSET_INT,
        "expireAfterWrite was already set to %s ns",
        expireAfterWriteNanos);
    checkArgument(duration >= 0, "duration cannot be negative: %s %s", duration, unit);
    this.expireAfterWriteNanos = unit.toNanos(duration);
    return this;
  }

Relevant Stackoverflow link which explains the issue: https://stackoverflow.com/questions/61810399/execute-google-cloud-dataflow-pipeline-from-spring-controller

To summarise, the method requires an additional parameter TimeUnit unit, which is not specified in the caller. I could not find any overloaded method which just has one parameter.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
mortiz143commented, Apr 20, 2021

fixed it with this,

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:guava:30.1.1-jre'
    }
}
7reactions
auroranilcommented, May 16, 2020

It is a Spring Boot application with dependencies specified in build.gradle file. GCSIO is being used by Apache Beam. The versions I am using are specified here below:

dependencies {
    compile group: 'org.apache.beam', name: 'beam-sdks-java-core', version: '2.20.0'
    compile group: 'org.apache.beam', name: 'beam-runners-google-cloud-dataflow-java', version: '2.20.0'
}

I was able to resolve this issue by adding guava version 29-0-jre to build.gradle file:

dependencies {
    compile group: 'org.apache.beam', name: 'beam-sdks-java-core', version: '2.20.0'
    compile group: 'org.apache.beam', name: 'beam-runners-google-cloud-dataflow-java', version: '2.20.0'
    compile group: 'com.google.guava', name: 'guava', version: '29.0-jre'
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

com.google.common.cache.CacheBuilder.maximumSize(J ...
java.lang.NoSuchMethodError is thrown at runtime because the JVM does not find the method in the referenced class.
Read more >
spotify/scio - Gitter
[error] (run-main-8) java.lang.NoSuchMethodError: com.google.common.cache.CacheBuilder.expireAfterWrite(Ljava/time/Duration ...
Read more >
com.google.common.cache Class CacheBuilder<K,V> - Guava
A builder of LoadingCache and Cache instances having any combination of the ... from the cache when any of maximumSize, maximumWeight, expireAfterWrite, ...
Read more >
com/google/common/cache/CacheBuilder
In the last weeks, we had to add guava as a dependency to avoid. java.lang.NoClassDefFoundError: com/google/common/cache/CacheBuilder. at hudson.model.
Read more >
[jira] [Comment Edited] (BEAM-9542) Where the ...
CacheBuilder.expireAfterWrite(Ljava/time/Duration;)Lcom/google/common/cache/CacheBuilder; java.lang.NoSuchMethodError: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found