java.lang.NoSuchMethodError: okio.BufferedSource.rangeEquals(JLokio/ByteString;)Z

Paras picture Paras · Jan 16, 2018 · Viewed 10.3k times · Source

I am integrating Outlook API and for making HTTP Calls I am using Retrofit version 2.3.0 and okHttp3 version 3.9.1. However when I'm making an HTTP Call, for example :

 // Create a logging interceptor to log request and responses
  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  interceptor.setLevel( HttpLoggingInterceptor.Level.BODY );

  OkHttpClient client = new OkHttpClient.Builder().addInterceptor( interceptor ).build();

  // Create and configure the Retrofit object
  Retrofit retrofit = new Retrofit.Builder().baseUrl( authority ).client( client ).addConverterFactory( JacksonConverterFactory.create() ).build();

  // Generate the token service
  TokenService tokenService = retrofit.create( TokenService.class );

  try
  {
     return tokenService.getAccessTokenFromAuthCode( tenantId, getAppId(), getAppPassword(), "authorization_code", authCode, getRedirectUrl() ).execute().body();
  }
  catch ( IOException e )
  {
     TokenResponse error = new TokenResponse();
     error.setError( "IOException" );
     error.setErrorDescription( e.getMessage() );
     return error;
  }

I am getting following exception :

 org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: okio.BufferedSource.rangeEquals(JLokio/ByteString;)Z

Below is my partial pom.xml :

    <!-- JACKSON DEPENDENCY FOR JSON PARSING -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.9.3</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.9.3</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.3</version>
    </dependency>

    <!-- RETROFIT DEPENDENCY FOR SENDING HTTP REQUESTS -->
    <dependency>
      <groupId>com.squareup.retrofit2</groupId>
      <artifactId>retrofit</artifactId>
      <version>2.3.0</version>
    </dependency>

    <dependency>
      <groupId>com.squareup.retrofit2</groupId>
      <artifactId>converter-jackson</artifactId>
      <version>2.3.0</version>
    </dependency>

    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>logging-interceptor</artifactId>
      <version>3.9.1</version>
    </dependency>

Can some one help me figure out, what's wrong with this?

Answer

Alex P. picture Alex P. · Jan 16, 2018
BufferedSource 

is in okio project version 1.13.0. Both dependencies com.squareup.retrofit2 and com.squareup.okhttp3 use this version. Also in this version this method is included. Version-wise it looks okay.

Local Environemnt

Now make sure to clear your maven repository. Maybe an old version got hung up somewhere. After that do a maven update project and a clean install.

Tomcat Environment

If this is happening in your tomcat make also sure to delete the work/Catalina/localhost/ folder, because sometimes things could be cached there.