OkHttpClient is final
See original GitHub issueWhat is the point of OkHttpClient be a final class?
Some frameworks, like spring, make intense use of proxies for almost everything.
I had a use case where I use to build the feign clients manually and now I’m trying to use spring-cloud-opentracing to do some distributed tracing.
One problem I’m facing is, on that package there’s a Aspect in order to decorate the client the their TracingClient, but the problem is: the aspect tries to make a proxy of the client implementation but the OkHttpClient is final.
tl;dr What is the possibility of making the OkHttpClient not final?
edit: The spring cloud opentracing feign can be found here: https://github.com/opentracing-contrib/java-spring-cloud/blob/master/instrument-starters/opentracing-spring-cloud-feign-starter/src/main/java/io/opentracing/contrib/spring/cloud/feign/FeignTracingAutoConfiguration.java#L80
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)

Top Related StackOverflow Question
Based on my understanding of the history of this project and it’s modules, the
Clientinterface is meant to be “open for extension, closed for modification” following the Open-Closed Principle. Both theApacheHttpClientand theOkHttpClientarefinalin order to adhere to this.With regards to
OpenTracing, there is anOpenTracingimplementation forFeignavailable that appears to indicate that you can use the providedOkHttpClientwithOpenTracinghttps://github.com/OpenFeign/feign-opentracing
In your particular case, you want to use Spring’s Open Tracing support for Spring Boot, which as you’ve pointed out, uses an
Aspectto instrument a Feign client that is not using aTracingClientexplicitly. Since you have mentioned that you are manually configuringFeign, if you use aTracingClientexplicitly, theAspectis not necessary.Looking at both
feign-opentracingand the Spring project, if you want to use a providedClient, you must useTracingClientdirectly.Now, with that said, I don’t see an issue with changing the current
Clientimplementations away fromfinal. Let’s ask the other contributors what they think.@velo, @spencergibb, @adriancole Thoughts?
Couldn’t do as you suggested.
I created a springboot autoconfiguration which creates a bean for TracingClient decorated with OkHttpClient. I think it’s probably for the best to keep OkHttpClient as final.