apps-android-commons icon indicating copy to clipboard operation
apps-android-commons copied to clipboard

[Bug]: App crashes on clicking Save (EditActivity)

Open kanahia1 opened this issue 1 year ago • 11 comments

Summary

App crashes on rotating image and clicking on save on few images.

Steps to reproduce

  1. Select a image from gallery
  2. Click on Edit Image
  3. Rotate Image
  4. 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

kanahia1 avatar Mar 20 '24 06:03 kanahia1

If you don't mind can i work on this?

neeldoshii avatar Mar 25 '24 11:03 neeldoshii

Hey @neeldoshii, can you please reproduce this issue first (Since it happens only for specific images). Maybe for those without exif data.

kanahia1 avatar Mar 25 '24 11:03 kanahia1

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.

neeldoshii avatar Mar 25 '24 12:03 neeldoshii

Great 👏 @neeldoshii , I feel this issue is caused by images with no exif data (as the logs suggest)

kanahia1 avatar Mar 25 '24 12:03 kanahia1

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?

neeldoshii avatar Mar 25 '24 13:03 neeldoshii

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. :-)

nicolas-raoul avatar Mar 25 '24 14:03 nicolas-raoul

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?

neeldoshii avatar Mar 25 '24 14:03 neeldoshii

Ah yes of course, and I am very sorry for the delay in assigning this!

nicolas-raoul avatar Mar 25 '24 14:03 nicolas-raoul

Did a quite more digging this PR #5569 solves this issue once it gets merged.

neeldoshii avatar Mar 25 '24 14:03 neeldoshii

Hey @neeldoshii, Thank you for your work. If possible, can you please share the updated patch?

kanahia1 avatar Mar 26 '24 14:03 kanahia1

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

neeldoshii avatar Mar 26 '24 14:03 neeldoshii

Strangely I am not able to reproduce this crash. Is it happening always for you two? Or in special conditions? Thanks! :-)

nicolas-raoul avatar Mar 29 '24 10:03 nicolas-raoul

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

  1. Download any image from google, check its exif data of the image. Make sure the image you taking has no exif data.
  2. Now use that image.

Basically crash happens when the image doesn't have any exif data at all.

neeldoshii avatar Mar 29 '24 10:03 neeldoshii

Indeed I am now able to reproduce, thanks!

nicolas-raoul avatar Mar 29 '24 10:03 nicolas-raoul