NoSuchMethodError: com.google.common.base.Stopwatch.createStarted () Lcom / google / common / base / Stopwatch

My application throws a NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch error NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch . I don’t know why, because 16.0.1 really contain this class, I checked. From what I researched, it looks like this is a mistake?

I also have this code for reference, although I think this is not a problem:

  FirewallRule rule = new PeriodicFirewallCounterRule(60, TimeUnit.SECONDS, new IpAddressCountingPolicy()); ((PeriodicFirewallCounterRule)rule).addHandler(new RateLimitationHandler(new UniqueLimitPolicy(10))); FirewallFilter firewallFiler = new FirewallFilter(getContext(), list(rule)); firewallFiler.setNext(ma); 

My application uses Restet APISpark:

  <dependency> <groupId>org.restlet.gae</groupId> <artifactId>org.restlet.ext.apispark</artifactId> <version>${version.restlet}</version> </dependency> 

When starting and accessing the api of the REST application, the application Error:

 [INFO] Caused by: java.lang.NoSuchMethodError: com.google.common.base.Stopwatch.createStarted()Lcom/google/common/base/Stopwatch; [INFO] at org.restlet.ext.apispark.internal.firewall.rule.counter.PeriodicCounter.<init>(PeriodicCounter.java:65) [INFO] at org.restlet.ext.apispark.internal.firewall.rule.PeriodicFirewallCounterRule$1.load(PeriodicFirewallCounterRule.java:86) [INFO] at org.restlet.ext.apispark.internal.firewall.rule.PeriodicFirewallCounterRule$1.load(PeriodicFirewallCounterRule.java:84) [INFO] at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3599) [INFO] at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2379) [INFO] at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2342) [INFO] at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2257) [INFO] ... 74 more 
+5
source share
6 answers

When using the org.restlet.ext.apispark extension org.restlet.ext.apispark resulting guava dependency is version 16.0.1 .

 Downloading: http://maven.restlet.com/com/google/guava/guava/16.0.1/guava-16.0.1.jar Downloading: http://repo.maven.apache.org/maven2/com/google/guava/guava/16.0.1/guava-16.0.1.jar Downloaded: http://repo.maven.apache.org/maven2/com/google/guava/guava/16.0.1/guava-16.0.1.jar (2176 KB at 711.7 KB/sec) 

It is included in an application built from scratch with the following maven configuration:

 <project (...)> <modelVersion>4.0.0</modelVersion> <groupId>org.restlet</groupId> <artifactId>restlet-apispark-firewall</artifactId> <name>${project.artifactId}</name> <packaging>jar</packaging> <version>1.0.0-snapshot</version> <properties> <java-version>1.7</java-version> <restlet-version>2.3.1</restlet-version> </properties> <dependencies> <dependency> <groupId>org.restlet.jse</groupId> <artifactId>org.restlet</artifactId> <version>${restlet-version}</version> </dependency> <dependency> <groupId>org.restlet.jse</groupId> <artifactId>org.restlet.ext.apispark</artifactId> <version>${restlet-version}</version> </dependency> </dependencies> <repositories> <repository> <id>maven-restlet</id> <name>Public online Restlet repository</name> <url>http://maven.restlet.com</url> </repository> </repositories> </project> 

I have included your code and it works fine on my side. No exception thrown ...

I think the older version of Guava comes from a different dependency. If you are using Maven, you should determine where this old version of guava comes from, and perhaps add an exception to the corresponding dependency. I hope it fixes your problem ...

Hope this helps, Thierry

+3
source

This is the solution that fixed the error:

First eliminate the old Guava dependency, and then:

  <dependency> <groupId>org.restlet.gae</groupId> <artifactId>org.restlet.ext.apispark</artifactId> <version>${version.restlet}</version> <exclusions> <exclusion> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.1</version> </dependency> 
+2
source

The class stopwatch loaded by this ClassLoader does not contain this method, not sure if it is called by several incompatible jars, as Jens says, or simply because 16.0.1 does not have this method. A simple check would be parsing the class using javap or a decompiler:

 javap -p Stopwatch.class 

And then check if this method is specified.

Edit: this method exists since 15.0, so I will also check the contents of your classpath.

+1
source

Referring to Oracle's NoSuchMethodError Documentation :

NoSuchMethodError: if the application tries to call the specified class method (either static or instance), and this class no longer has a method definition.

Usually this error is caught by the compiler; this error can only occur at run time if the class definition is incompatibly changed .

I think you have this exception because you have several versions of this jar in your classpath, and since the createStarted() method is available from version 15.0 , I would say that you have another old version, probably due to a dependency problem.

+1
source

Going to the latest version of Guava did it for me

0
source

In my case, one of my Maven dependencies was building a new version of Guava (16.0.1), which apparently does not have this method. When I added an exception to this dependency in my pom.xml , an older (correct) version of Guava was picked up by another of my dependencies instead, and then it worked.

You can find this by printing a dependency tree through mvn dependency:tree , and then looking to see if it is building a new version of guava. You may need to add a few exceptions to figure this out.

0
source

Source: https://habr.com/ru/post/1214662/


All Articles