Skip to content

Commit 0dfc2c3

Browse files
committed
Fix StackOverFlowError due to interceptors being added in loop
1 parent 5aa8ef4 commit 0dfc2c3

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/com/github/rishabh9/riko/upstox/common/ServiceGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public <S> S createService(@Nonnull final Class<S> serviceClass,
166166
public <S> S createService(@Nonnull final Class<S> serviceClass,
167167
@Nullable final AuthHeaders headers) {
168168

169+
httpClient.interceptors().clear(); // Fix StackOverFlowError
170+
169171
enableAuthentication(headers);
170172
if (log.isDebugEnabled()) {
171173
enableHttpLogging();

src/main/java/com/github/rishabh9/riko/upstox/common/interceptors/AuthenticationInterceptor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import okhttp3.Response;
3030

3131
import java.io.IOException;
32+
import java.util.Objects;
3233

3334
/**
3435
* Retrofit2 interceptor to add common authentication headers to every request.
@@ -54,4 +55,18 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
5455
Request request = builder.build();
5556
return chain.proceed(request);
5657
}
58+
59+
@Override
60+
public boolean equals(Object o) {
61+
if (this == o) return true;
62+
if (o == null || getClass() != o.getClass()) return false;
63+
AuthenticationInterceptor that = (AuthenticationInterceptor) o;
64+
return Objects.equals(authToken, that.authToken) &&
65+
Objects.equals(apiKey, that.apiKey);
66+
}
67+
68+
@Override
69+
public int hashCode() {
70+
return Objects.hash(authToken, apiKey);
71+
}
5772
}

0 commit comments

Comments
 (0)