Handle case where user uploads image with empty title (whitespace)
See original GitHub issueSummary:
Try uploading an image with an empty title(only spaces) and description. App crashes on clicking next.
Add System logs:
Error pid or pid not exist
2018-06-18 19:26:50.123 1821-1821/fr.free.nrw.commons.debug E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2018-06-18 19:26:50.545 1821-1821/fr.free.nrw.commons.debug E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
2018-06-18 19:26:52.982 1821-1821/fr.free.nrw.commons.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: fr.free.nrw.commons.debug, PID: 1821
java.lang.StringIndexOutOfBoundsException: length=0; regionStart=0; regionLength=1
at java.lang.String.substring(String.java:1931)
at fr.free.nrw.commons.Utils.capitalize(Utils.java:79)
at fr.free.nrw.commons.PageTitle.<init>(PageTitle.java:25)
at fr.free.nrw.commons.Utils.makeThumbBaseUrl(Utils.java:54)
at fr.free.nrw.commons.Media.getImageUrl(Media.java:173)
at fr.free.nrw.commons.contributions.ContributionDao.toContentValues(ContributionDao.java:95)
at fr.free.nrw.commons.contributions.ContributionDao.save(ContributionDao.java:62)
at fr.free.nrw.commons.upload.UploadService.queue(UploadService.java:153)
at fr.free.nrw.commons.upload.UploadController$2.onPostExecute(UploadController.java:201)
at fr.free.nrw.commons.upload.UploadController$2.onPostExecute(UploadController.java:132)
at android.os.AsyncTask.finish(AsyncTask.java:667)
at android.os.AsyncTask.-wrap1(AsyncTask.java)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6379)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Expected behavior:
App should gracefully handle empty values.
Observed behavior:
App crashes!
Device and Android version:
What make and model device (e.g., Samsung J7) did you encounter this on? What Android version (e.g., Android 4.0 Ice Cream Sandwich or Android 6.0 Marshmallow) are you running? Is it the stock version from the manufacturer or a custom ROM ?
Commons app version:
You can find this information by going to the navigation drawer in the app and tapping ‘About’
Screen-shots:
Can be created by pressing the Volume Down and Power Button at the same time on Android 4.0 and higher.
Would you like to work on the issue?
Please let us know whether you want to fix the issue by yourself. If not, anyone can get the issue assigned to them.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Yes, I agree with you @misaochan. That check was already present, it was just not checking for whitespaces.
Before the fix:
After the fix:
Yup this is fixed now. (Y)
Currently merged to the feature branch for 2.8.0.