twotoasters / hoot

A powerful, flexible, lightweight Android library for dealing with RESTful endpoints.
Apache License 2.0
26 stars 10 forks source link

NullPointerException when request deserializer is null. #3

Closed twaddington closed 11 years ago

twaddington commented 11 years ago

There is some broken logic in HootRequest.java:

    void deserializeResult() throws IOException {
        if (mDeserializer == null
                || (mDeserializer != null && mDeserializer
                        .isStreamDeserializer())) {
            // TODO: This block will be executed if mDeserializer is null, however, this line then
            // attempts to execute the deserialize method on a null object.
            mResult.setDeserializedResult(mDeserializer.deserialize(mResult
                    .getResponseStream()));
        } else {
            mResult.setResponse(convertStreamToString(mResult
                    .getResponseStream()));
            mResult.setDeserializedResult(mDeserializer.deserialize(mResult
                    .getResponseString()));
        }
    }

https://github.com/twotoasters/hoot/blob/master/src/com/twotoasters/android/hoot/HootRequest.java#L333

I'm not sure how to best fix this yet. Perhaps if deserializer is null we could just automatically deserialize the message body to a string. Any ideas?

For HEAD and DELETE requests a deserializer won't be necessary since the response body is empty.

bjdupuis commented 11 years ago

Great catch. I'll address it. Yes, in the absence of a deserializer we'll pop out a string if any.

bjdupuis commented 11 years ago

Addressed in 0254cf40d1a109d806023dd9c01cfb6faa5f0d3f.

bjdupuis commented 11 years ago

Actually, that commit was bad. I like this one better c4bf8a18fd6ce9d5d8598a486ac0914b294c6bad.

twaddington commented 11 years ago

Okay, yeah, that seems more correct.