apps-android-commons
apps-android-commons copied to clipboard
[Bug]: App crashes on clicking Save (EditActivity)
Summary
App crashes on rotating image and clicking on save on few images.
Steps to reproduce
- Select a image from gallery
- Click on Edit Image
- Rotate Image
- Click on save Image
Expected behaviour
App should not crash and rotated image should be shown
Actual behaviour
App crashes
Device name
Samsung S21
Android version
Android 14
Commons app version
4.2.1-debug-issues5439
Device logs
java.lang.NullPointerException
at fr.free.nrw.commons.edit.EditActivity.copyExifData(EditActivity.kt:260)
at fr.free.nrw.commons.edit.EditActivity.getRotatedImage(EditActivity.kt:241)
at fr.free.nrw.commons.edit.EditActivity.init$lambda$3(EditActivity.kt:125)
at fr.free.nrw.commons.edit.EditActivity.$r8$lambda$fIjJEeuPIZcPAnhPtUzdHmWgXF0(Unknown Source:0)
at fr.free.nrw.commons.edit.EditActivity$$ExternalSyntheticLambda2.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:8043)
at android.widget.TextView.performClick(TextView.java:17816)
at android.view.View.performClickInternal(View.java:8020)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:31850)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8893)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Screen-shots
https://github.com/commons-app/apps-android-commons/assets/114223204/f48ad2c7-82ad-4220-85f0-42713f432c3b
Would you like to work on the issue?
Yes
If you don't mind can i work on this?
Hey @neeldoshii, can you please reproduce this issue first (Since it happens only for specific images). Maybe for those without exif data.
Reproduced. For me the bug happened to me at first image.
Not sure what its causing, I am investigating it. This is giving crash to me everytime.
Great 👏 @neeldoshii , I feel this issue is caused by images with no exif data (as the logs suggest)
I feel this issue is caused by images with no exif data (as the logs suggest)
Thank you @kanahia1 a lot for this, it helped me exactly for a pinned point for the cause of issue and fix. Below is the code patch that ~solves the issue.~ Edit : App crash is solved but image doesn't gets rotated on save since rotated image results in null. Needs more change to fix the rotation.
fun getRotatedImage() {
val filePath = imageUri.toUri().path
val file = filePath?.let { File(it) }
val rotatedImage = file?.let { vm.rotateImage(imageRotation, it) }
if (rotatedImage == null) {
Toast.makeText(this, "Failed to rotate to image", Toast.LENGTH_LONG).show()
}
- val editedImageExif = rotatedImage?.path?.let { ExifInterface(it) }
- copyExifData(editedImageExif)
+ val editedImageExif: ExifInterface?
+ if (rotatedImage?.path != null) {
+ editedImageExif = ExifInterface(rotatedImage.path)
+ copyExifData(editedImageExif)
+ }
val resultIntent = Intent()
resultIntent.putExtra("editedImageFilePath", rotatedImage?.toUri()?.path ?: "Error");
setResult(RESULT_OK, resultIntent);
finish();
}
If you would like, I can submit a pull request with this fix, or if you prefers to work on it, use this patch and this will fix the app crash.
CC : @nicolas-raoul when we have no exif data of image do we want to show snackbar/toast to user that this image doesn't contain exif information?
Assigning to Kanahia due to "Would you like to work on the issue? Yes"
The app already sends a warning when the picture seems to not have been taken by the user, we use EXIF presence to detect this. So no need to send another warning. :-)
Assigning to Kanahia due to "Would you like to work on the issue? Yes"
Sure @nicolas-raoul, I have fixed the issue can I provide the next updated patch for @kanahia1 for reference?
Ah yes of course, and I am very sorry for the delay in assigning this!
Did a quite more digging this PR #5569 solves this issue once it gets merged.
Hey @neeldoshii, Thank you for your work. If possible, can you please share the updated patch?
Hey @neeldoshii, Thank you for your work. If possible, can you please share the updated patch?
As said, this issue is already solved in PR #5569
Strangely I am not able to reproduce this crash. Is it happening always for you two? Or in special conditions? Thanks! :-)
Strangely I am not able to reproduce this crash.
Is it happening always for you two? Or in special conditions?
Thanks! :-)
Here are the steps
- Download any image from google, check its exif data of the image. Make sure the image you taking has no exif data.
- Now use that image.
Basically crash happens when the image doesn't have any exif data at all.
Indeed I am now able to reproduce, thanks!