Skip to content
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

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

Closed
kanahia1 opened this issue Mar 20, 2024 · 14 comments · Fixed by #5670
Closed

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

kanahia1 opened this issue Mar 20, 2024 · 14 comments · Fixed by #5670
Assignees
Labels

Comments

@kanahia1
Copy link
Contributor

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

WhatsApp.Video.2024-03-20.at.12.19.24_c0b948ec.mp4

Would you like to work on the issue?

Yes

@kanahia1 kanahia1 added the bug label Mar 20, 2024
@kanahia1 kanahia1 changed the title [Bug]: App crashes on rotating the image [Bug]: App crashes on clicking Save (EditActivity) Mar 20, 2024
@neeldoshii
Copy link
Contributor

neeldoshii commented Mar 25, 2024

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

@kanahia1
Copy link
Contributor Author

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

@neeldoshii
Copy link
Contributor

neeldoshii commented Mar 25, 2024

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.

@kanahia1
Copy link
Contributor Author

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

@neeldoshii
Copy link
Contributor

neeldoshii commented Mar 25, 2024

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?

@nicolas-raoul
Copy link
Member

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

@neeldoshii
Copy link
Contributor

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?

@nicolas-raoul
Copy link
Member

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

@neeldoshii
Copy link
Contributor

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

@kanahia1
Copy link
Contributor Author

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

@neeldoshii
Copy link
Contributor

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

@nicolas-raoul
Copy link
Member

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

@neeldoshii
Copy link
Contributor

neeldoshii commented Mar 29, 2024

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.

@nicolas-raoul
Copy link
Member

Indeed I am now able to reproduce, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants