From 0dfc2c3c555a97e178b43fe88facd83e47e5d5a0 Mon Sep 17 00:00:00 2001 From: Rishabh Joshi Date: Wed, 24 Oct 2018 18:50:43 +0530 Subject: [PATCH] Fix StackOverFlowError due to interceptors being added in loop --- .../riko/upstox/common/ServiceGenerator.java | 2 ++ .../interceptors/AuthenticationInterceptor.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/com/github/rishabh9/riko/upstox/common/ServiceGenerator.java b/src/main/java/com/github/rishabh9/riko/upstox/common/ServiceGenerator.java index 90dbe83..2f38edb 100644 --- a/src/main/java/com/github/rishabh9/riko/upstox/common/ServiceGenerator.java +++ b/src/main/java/com/github/rishabh9/riko/upstox/common/ServiceGenerator.java @@ -166,6 +166,8 @@ public S createService(@Nonnull final Class serviceClass, public S createService(@Nonnull final Class serviceClass, @Nullable final AuthHeaders headers) { + httpClient.interceptors().clear(); // Fix StackOverFlowError + enableAuthentication(headers); if (log.isDebugEnabled()) { enableHttpLogging(); diff --git a/src/main/java/com/github/rishabh9/riko/upstox/common/interceptors/AuthenticationInterceptor.java b/src/main/java/com/github/rishabh9/riko/upstox/common/interceptors/AuthenticationInterceptor.java index c300f76..1f59f75 100644 --- a/src/main/java/com/github/rishabh9/riko/upstox/common/interceptors/AuthenticationInterceptor.java +++ b/src/main/java/com/github/rishabh9/riko/upstox/common/interceptors/AuthenticationInterceptor.java @@ -29,6 +29,7 @@ import okhttp3.Response; import java.io.IOException; +import java.util.Objects; /** * Retrofit2 interceptor to add common authentication headers to every request. @@ -54,4 +55,18 @@ public Response intercept(Interceptor.Chain chain) throws IOException { Request request = builder.build(); return chain.proceed(request); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AuthenticationInterceptor that = (AuthenticationInterceptor) o; + return Objects.equals(authToken, that.authToken) && + Objects.equals(apiKey, that.apiKey); + } + + @Override + public int hashCode() { + return Objects.hash(authToken, apiKey); + } } \ No newline at end of file