[Bug report] ML Kit Document Scanner crashes on discard
Describe the bug After the implementation, app launching and document scanning working fine . But if discard the scanning by close button app crashes in specific device (Samsung Tab)
To Reproduce Example Steps to reproduce the behavior in sample app:
- Set page limit to any number(sample: 5)
- Click on 'Scan'
- Click on capture button
- Discard scanning by clicking close button
- Getting error:
Failed to handle scanning result java.lang.IllegalStateException: Failed to handle result at com.google.mlkit.vision.documentscanner.internal.zzg.run(com.google.android.gms:play-services-mlkit-document-scanner@@16.0.0-beta1:12) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:246) at android.os.HandlerThread.run(HandlerThread.java:67) - With this error app crashes
If applicable, please include code snippet and sample input(image, video, text, etc)
Expected behavior A clear and concise description of what you expected to happen.
SDK Info:
- 'com.google.android.gms:play-services-mlkit-document-scanner:16.0.0-beta1'
Smartphone:
- Device/Simulator: Samsung Galaxy Tab A
- Device/Simulator OS: Android 11 API 30
Development Environment: (For Android issue feel free to skip this section)
- IDE Eversion: [e.g. Xcode 13.1, Android Studio 4.2]
- Laptop/Desktop: [e.g. iMac Pro (2017), HP Z840 Workstation]
- Laptop/Desktop OS/version: [e.g. macOS 12.0.1]
Same for me. Android 14 Pixel 6
Caught the same issue on Android 10, device: Xiaomi Mi A2 Lite
Failed to handle scanning result java.lang.IllegalStateException: Failed to handle result at com.google.mlkit.vision.documentscanner.internal.zzg.run(com.google.android.gms:play-services-mlkit-document-scanner@@16.0.0-beta1:12) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.os.HandlerThread.run(HandlerThread.java:67)
i too
I also get this issue even after capturing a photo. My device is: Galaxy Tab S6 Lite / Anndroid 13.
A workaround that is working for me is to use the SCANNER_MODE_BASE instead of SCANNER_MODE_FULL
https://developers.google.com/android/reference/com/google/mlkit/vision/documentscanner/GmsDocumentScannerOptions#public-static-final-int-scanner_mode_base
Suggested in the Google Issue tracker
I use mode SCANNER_MODE_BASE and the issue is still there. I'm getting it on Android 16, Play Services 25.08.32
Thanks for flagging this.
One scenario I was able to replicate is this error gets logged, but app which launches won't crash.
@dprasath can you please help with more details of which app is getting crashed ? If possible, also share code snippet of how you are launching the GmsDocumentScanner API
I agree We are not seeing any crashes on our crash dashboards Only the GMSScanningActivity closes itself without any results.
Would it be possible to get this from the activity results or anywhere else
Would it be possible to get this from the activity results or anywhere else
Didn't completely get you. You mean fetching the information whether the scanning session is discarded or not ? You should be able to use Activity.RESULT_CANCELED vs Activity.RESULT_OK to differentiate them.
Since getting the actual crash wouldn't be possible You are suggesting that we can rely on the Activity.RESULT_CANCELED vs Activity.RESULT_OK
I'm asking this because I'm not fully able to recreate this scenario but a lot of our users are complaining on this specific issue
Any tips on recreating this since you were able to?
Also even the scanner on Google drive crashes if it's crashing in your app I'm guessing because it uses the same library
No, what I meant to say is:: User performing discard action is an expected behaviour. We are planning to fix internal logic to not log this as an IllegalStateException .
Even now, I don't think we should treat this as a crash, because the logic catches this exception and handles it appropriately, so no app crash should be noticed.
Please let us know if you are noticing any app crashes. (Basically, if we are discarding, the expected behaviour is that the activity closes without any result data ) . We can pre-check resultCode() to handle if the result has result data or not.
Steps to reproduce::
- Open the scanner.
- Discard / close the activity without performing any document scan.
- We should be able to see this error log.
This is why i should read things correctly
I misread this github issue as a duplicate of this Google Bug Tracker
But again Very similar crash stacktrace
Please take note bug exits in Dos programing and since is called bug we notice it and we need ot fix it so that the software will not crash. the reason is as the value ethics or being ethical because is himan nature. the small problem will be a big problem if is not solved. pleaee be concerned about the surrounding ad the environment and the energies are tensed and also negative. if no yes to strengthen the formula the trample is just like a unfinished programme q
On Tue, 18 Mar 2025, 16:36 Avinash Vadlamudi, @.***> wrote:
Thanks for flagging this.
One scenario I was able to replicate is this error gets logged, but app which launches won't crash.
@dprasath https://github.com/dprasath can you please help with more details of which app is getting crashed ? If possible, also share code snippet of how you are launching the GmsDocumentScanner API
— Reply to this email directly, view it on GitHub https://github.com/googlesamples/mlkit/issues/866#issuecomment-2732112491, or unsubscribe https://github.com/notifications/unsubscribe-auth/BQBT256ZRXCYSBZ3LDFHLHD2U7LJJAVCNFSM6AAAAABNDXV27OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZSGEYTENBZGE . You are receiving this because you are subscribed to this thread.Message ID: @.***> [image: avivadla8]avivadla8 left a comment (googlesamples/mlkit#866) https://github.com/googlesamples/mlkit/issues/866#issuecomment-2732112491
Thanks for flagging this.
One scenario I was able to replicate is this error gets logged, but app which launches won't crash.
@dprasath https://github.com/dprasath can you please help with more details of which app is getting crashed ? If possible, also share code snippet of how you are launching the GmsDocumentScanner API
— Reply to this email directly, view it on GitHub https://github.com/googlesamples/mlkit/issues/866#issuecomment-2732112491, or unsubscribe https://github.com/notifications/unsubscribe-auth/BQBT256ZRXCYSBZ3LDFHLHD2U7LJJAVCNFSM6AAAAABNDXV27OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZSGEYTENBZGE . You are receiving this because you are subscribed to this thread.Message ID: @.***>
What is bro even on about 💀