Skip to content

Fix for java.lang.ClassCastException in BinaryHttpResponseHandler #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

rishabhmhjn
Copy link
Contributor

I've got loads of ClassCastException crash reports and this commit might fix the bug.
I'm not yet sure of why this bug exists in the first place.
Please confirm this and let me know if I'm doing something wrong here.
Thanks

java.lang.ClassCastException: java.lang.String cannot be cast to byte[]
  at com.loopj.android.http.BinaryHttpResponseHandler.handleMessage(BinaryHttpResponseHandler.java:145)
  at com.loopj.android.http.AsyncHttpResponseHandler$1.handleMessage(AsyncHttpResponseHandler.java:84)

@feichh
Copy link

feichh commented Jun 7, 2013

Q: why are you using a BinaryResponseHandler, if you receive a String?
I thought that was AsyncHttpResponseHandler's purpose?

cheers

@feichh
Copy link

feichh commented Jun 7, 2013

@rishabhmhjn
Copy link
Contributor Author

I'm using it for downloading images. I'm not sure why it is sometimes taken as a String!
Any idea?

@feichh
Copy link

feichh commented Jun 7, 2013

ah i c, that's odd indeed. Did you look at what happens in AsyncHttpRequest.makeRequest() ?

@rishabhmhjn
Copy link
Contributor Author

This is where I am having a big problem.
I never got this error while testing but have got a lot of crash reports in Google Analytics.
I'm still unable to replicate this situation.

@rishabhmhjn
Copy link
Contributor Author

@kakueki61
Copy link

I also encountered the similar problem.
In my case, this problem occurs when socket time out exception occurs. I think that's because I cannot get the binary image at that time.

@rishabhmhjn
Copy link
Contributor Author

@kakueki61 yes. if it was a failure, it used to give an exception.

@synchrok
Copy link

synchrok commented Jul 9, 2013

@kakueki61 that's right.
I think master can not test this problem cause of it needs bad internet speed like occurs socket timeout exception. This problem must be resolved as soon as possible..

@loopj
Copy link
Collaborator

loopj commented Aug 19, 2013

Hi @rishabhmhjn I want to merge this pull request.
Can you merge in master?

@rishabhmhjn
Copy link
Contributor Author

I think I did it! Are you facing errors while merging?

@loopj
Copy link
Collaborator

loopj commented Aug 19, 2013

It doesn't look like youve done it. Can you try the following:

  • git remote add upstream git@github.com:loopj/android-async-http.git
  • git fetch upstream
  • git merge upstream/master
  • git push origin master

@rishabhmhjn
Copy link
Contributor Author

I realized that there is a conflict in BinaryHttpResponseHandler.java

My changes | Your changes

<<<<<<< HEAD
                String res1 = response[1] == null ? "" : response[1].toString();
                handleFailureMessage((Throwable) response[0], res1);
=======
                handleFailureMessage((Throwable)response[0], (byte[]) response[1]);
>>>>>>> loopj/master

I have put my code in production and all the errors have gone.
So should I override my changes onto the above?

@loopj
Copy link
Collaborator

loopj commented Aug 19, 2013

Actually @rishabhmhjn it looks like this bug has already been fixed with this commit: 7d10a63

@loopj loopj closed this Aug 19, 2013
@rishabhmhjn
Copy link
Contributor Author

Alright, great.
Thanks.

@djangoq
Copy link

djangoq commented Aug 26, 2013

Hi

I think rishabhmhjn's proposal should still be taken into master build. When socket timeout occurs it still gives classcastexception. But with proposed fix which with toString cast seems to work ok.

@advantej
Copy link

advantej commented Oct 2, 2013

@loopj I'm still running into the classcastexception with the latest codebase. I'm using it to download images and when the phone has no connection (say airplane mode), it crashes everytime with a classcastexception.

@k0rtess
Copy link

k0rtess commented Nov 7, 2013

I get this exception often on some slow public wifi's.
So is there some fix already available ?

@smarek
Copy link
Member

smarek commented Nov 7, 2013

@k0rtess this issue should be fixed, if it appeared again, please create new issue and post full stacktrace. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants