question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassCastException in Feign's default Client implementation, when UrlStreamHandlerFactory is overwritten

See original GitHub issue

While running a job via spark/hadoop, before doing that, i fetch the job arguments from a remote service using Feign 9.5.0 (to get out of the way of the jar dependency hell within spark/hadoop)

When the client connect, i get this:

7/12/19 20:07:28 ERROR MachineLearningJob$: Error during block list computation: java.lang.ClassCastException: org.apache.hadoop.fs.FsUrlConnection cannot be cast to java.net.HttpURLConnection at feign.Client$Default.convertAndSend(Client.java:80) at feign.Client$Default.execute(Client.java:73) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76) at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103) ...

The Feign-Client code looks like this:

HttpURLConnection convertAndSend(Request request, Options options) throws IOException { final HttpURLConnection connection = (HttpURLConnection) new URL(request.url()).openConnection(); ...

So it looks like, spark/hadoop does set its own urlstreamhandlerfactory for http/https, that opens its own URLConnection implementation, which are not of Http(s)UrlConnection (https://issues.apache.org/jira/browse/HADOOP-14598) But this is what Feign’s default client assumes.

My suggestion is to extend checking your assumptions and if they are not met, to get out of the way with a proper exception. Maybe a hint, that someone has set its own handler. Maybe with a hint, that there are other client implementation (feign-okhttp, feign-httpclient), just something to speed up debugging, when this occurs. Maybe documenting it in the source code is also enough. This might save someone else’s lifetime!

What do you think?

Happy holidays

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
okrischecommented, Mar 8, 2018

It is a bug. Feign’s default client assumes, that URL#openConnection returns HttpUrlConnection. Which is not true, if someone (in my case it was spark/hadoop) has overwritten the default factory within URL.

0reactions
okrischecommented, Dec 26, 2019

(It is still a bug, though, and it can appear at any time again. Suggestion was to go out of the way with a proper exception, if expectation does not meet reality: Feign Client only works, if factory returns Http(s)UrlConnection.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

All Articles
(thick client deployment) - git · How to include TEMPLATE_CONTEXT_PROCESSORS by default in the new TEMPLATES parameter in Django 1.10 - python ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found