-
-
Notifications
You must be signed in to change notification settings - Fork 735
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
Fixed bug in ParseOkHttpClient which didn't handle ParseFile File uploads properly. #364
Conversation
…oads correctly. This check was unnecessary and in the event of a ParseFileHttpBody it would result in a null body for the Http POST which throws an exception. Alternatively it could be replaced with the following: if(parseBody instanceof ParseByteArrayHttpBody || parseBody instanceof ParseFileHttpBody) { okHttpRequestBody = new ParseOkHttpRequestBody(parseBody); } However both of those classes extend ParseHttpBody and they are the only classes that do so and the constructor for ParseOkHttpRequestBody is expecting type ParseHttpBody which they both extend so it seems as though the check is unnecessary. This fixes File uploads as part of a ParseFile. Previously it was throwing the exception: com.parse.ParseException: java.lang.IllegalArgumentException: method POST must have a request body. 01-22 14:03:12.982 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:114) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at android.os.Handler.handleCallback(Handler.java:739) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at android.os.Looper.loop(Looper.java:148) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at java.lang.reflect.Method.invoke(Native Method) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 01-22 14:03:12.983 24657-24657/com.plus11.ncredible W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 01-22 14:03:12.984 24657-24657/com.plus11.ncredible W/System.err: Caused by: java.lang.IllegalArgumentException: method POST must have a request body. 01-22 14:03:12.984 24657-24657/com.plus11.ncredible W/System.err: at com.squareup.okhttp.Request$Builder.method(Request.java:256) 01-22 14:03:12.984 24657-24657/com.plus11.ncredible W/System.err: at com.squareup.okhttp.Request$Builder.post(Request.java:229) 01-22 14:03:12.985 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseOkHttpClient.getRequest(ParseOkHttpClient.java:157) 01-22 14:03:12.985 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseOkHttpClient.executeInternal(ParseOkHttpClient.java:66) 01-22 14:03:12.985 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:158) 01-22 14:03:12.985 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParsePlugins$1.intercept(ParsePlugins.java:115) 01-22 14:03:12.985 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:147) 01-22 14:03:12.985 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseHttpClient.execute(ParseHttpClient.java:122) 01-22 14:03:12.986 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseRequest$3.then(ParseRequest.java:136) 01-22 14:03:12.986 24657-24657/com.plus11.ncredible W/System.err: at com.parse.ParseRequest$3.then(ParseRequest.java:133) 01-22 14:03:12.986 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task$15.run(Task.java:839) 01-22 14:03:12.986 24657-24657/com.plus11.ncredible W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105) 01-22 14:03:12.986 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task.completeAfterTask(Task.java:830) 01-22 14:03:12.986 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task.continueWithTask(Task.java:642) 01-22 14:03:12.987 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task.continueWithTask(Task.java:653) 01-22 14:03:12.987 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task$13.then(Task.java:745) 01-22 14:03:12.987 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task$13.then(Task.java:733) 01-22 14:03:12.987 24657-24657/com.plus11.ncredible W/System.err: at bolts.Task$15.run(Task.java:839) 01-22 14:03:12.987 24657-24657/com.plus11.ncredible W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 01-22 14:03:12.987 24657-24657/com.plus11.ncredible W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 01-22 14:03:12.988 24657-24657/com.plus11.ncredible W/System.err: at java.lang.Thread.run(Thread.java:818)
Fixed bug in ParseOkHttpClient which didn't handle ParseFile File upl…
By analyzing the blame information on this pull request, we identified @grantland and @wangmengyan95 to be potential reviewers. |
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Hi @michaelgarnerdev, good catch. This change make sense to me. Is it possible for you to add a unit test case to cover this case? Thanks! |
Hi @wangmengyan95, I looked into adding a test case, but it would seem there is already a test case for creating a ParseFile with a File and saveAsync. It would appear to me, that it is covered, but if not I'm not too sure how I would write one to test something this deep in the APIs. |
Also, where is the appropriate place for feature requests? I would like an additional constructor in ParseFile to create ParseFile like this: |
if(parseBody instanceof ParseByteArrayHttpBody) { | ||
okHttpRequestBody = new ParseOkHttpRequestBody(parseBody); | ||
} | ||
okHttpRequestBody = new ParseOkHttpRequestBody(parseBody); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will cause NPE if parseBody
is null
when actually executing the request since all the methods on `ParseOkHttpRequestBody use it: https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParseOkHttpClient.java#L281
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, I do not think it will cause NPE
sicne we only use okHttpRequestBody
for POST and PUT request. In that situation parseBody
should not be null
.
If we add the null checking, when the POST or PUT has a null
body, okHttpRequestBuilder
will throw IllegalArgumentException
.
If we do not add the null checking, when the POST or PUT has a null
body, the exception will be thrown when we actually write the body.
In this situation, I think probably it is better to add the null checking. Let's prevent the error as early as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelgarnerdev Mind adding the null check?
@wangmengyan95 any idea why integration tests didn't catch this issue? |
@grantland @michaelgarnerdev our test cases related to httpClient is here. In the test cases, we just use the |
@michaelgarnerdev updated the pull request. |
Why isn't this merged? Any known workaround? |
Waiting on a revision to the PR to add |
I'm no longer developing with Parse so I recommend someone else does this. On Mon, Nov 7, 2016, 14:39 Grantland Chew notifications@github.com wrote:
|
PR'd #542 |
This PR can be closed in lieu of #542 |
This check was unnecessary and in the event of a ParseFileHttpBody it would result in a null body for the Http POST which throws an exception.
Alternatively it could be replaced with the following:
However both of those classes extend ParseHttpBody and they are the only classes that do so and the constructor for ParseOkHttpRequestBody is expecting type ParseHttpBody which they both extend so it seems as though the check is unnecessary.
This fixes File uploads as part of a ParseFile. Previously it was throwing the exception: