somkiattha / opendatakit

Automatically exported from code.google.com/p/opendatakit
0 stars 0 forks source link

WebUtils.createOpenRosaHttpHead can throw uncaught IllegalArgumentException #1146

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Enter an ODK Collect URL with a leading space (e.g. " https://foobar.com")
2. Attempt to submit a form

What is the expected output? What do you see instead?
Expected outcome: ODK Collect should indicate that the URL is invalid
Actual outcome: ODK Collect crashes

Please provide any additional information below.
WebUtils.createOpenRosaHttpHead uses java.net.URI.create without catching the 
thrown IllegalArgumentException.  This only manifests itself when forms are 
uploaded.  This bit us during a training exercise when half our users were 
unable to upload forms from the field with ODK crashing when they tried.  When 
I got the devices back, I found this in the logfile:
E/AndroidRuntime(16668): Caused by: java.lang.IllegalArgumentException: Illegal 
character in scheme at index 0:  https://<URI removed>
E/AndroidRuntime(16668):    at java.net.URI.create(URI.java:733)
E/AndroidRuntime(16668):    at 
org.odk.collect.android.utilities.WebUtils.createOpenRosaHttpHead(WebUtils.java:
204)
etc

Fix is simple:
1) trim() the URI string before attempting to create a URI, to make this more 
robust
2) Delcare that the method throws IllegalArgumentException, and catch it in 
InstanceUplaoderTask.uploadOneSubmission, along with the other exceptions that 
are caught and logged properly there.

Original issue reported on code.google.com by inverar...@gmail.com on 26 May 2015 at 10:01