Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.Interceptor$Chain.readTimeoutMillis()I #326

Open
peterlai-roboops opened this issue Apr 19, 2018 · 6 comments

Comments

@peterlai-roboops
Copy link

peterlai-roboops commented Apr 19, 2018

When ever i tried to register, i get this error.
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.Interceptor$Chain.readTimeoutMillis()I
at com.orbitz.consul.cache.TimeoutInterceptor.intercept(TimeoutInterceptor.java:28)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
at okhttp3.RealCall.execute(RealCall.java:69)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
at com.orbitz.consul.AgentClient.ping(AgentClient.java:61)
at com.orbitz.consul.Consul$Builder.build(Consul.java:617)
at Application.main(Application.java:40)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

`
Consul consul = Consul.builder().build(); // connect to Consul on localhost
AgentClient agentClient = consul.agentClient();

    String serviceName = "MyService";
    String serviceId = "MyService-Peter1";

    
    agentClient.register(8080, 3L, serviceName, serviceId); // registers with a TTL of 3 seconds
    try {
        agentClient.pass(serviceId);
    } catch (NotRegisteredException e) {
        System.out.println("peter " + e);
    }

`

@yfouquet
Copy link
Collaborator

Hi @tiny-cababge,

Can you please give us more details?

  • the version of the consul-client library
  • the classifier of the consul-client library (if any)
  • the version(s) of okhttp in your dependency tree.

It looks like you are not using (at runtime) the same version of okhttp.
Note that:

@peterlai-roboops
Copy link
Author

peterlai-roboops commented Apr 19, 2018

Yea, adding the following dep works.

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>3.9.0</version>
    </dependency>

How come these wasn't packaged as part of the build?

@yfouquet
Copy link
Collaborator

I cannot tell you without without knowing what you use. Which version of consul-client do you use? Do you use the shaded artifact? Is there any other version on okhttp in your dependency tree?

Seeing the exception (NoSuchMethodError), you found the class, so you had a okhttp in your classpath. My guess is that an older version of okhttp was used (maybe because of other dependencies) and you got a dependency conflict. You should find out the reason as your fix may add new issues. Note that the shaded version protects you from such conflicts.

@yfouquet
Copy link
Collaborator

Hi @tiny-cababge,
Is there any update on your issue?
Either you consider it fixed and you can close the issue; or you still have issue and we'll be glad to help you.

@peterlai-roboops
Copy link
Author

peterlai-roboops commented Apr 26, 2018 via email

@yfouquet yfouquet removed the question label Jun 1, 2018
@bearrito
Copy link

I can replicate this is the latest release.

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

No branches or pull requests

3 participants