1

I have a piece of code:

            try {
                it.write()
            } catch (e : ErrnoException) {
                Logger.d("Playlist ${location.parentFile} could not be saved:", e)
            } catch (e: Exception) {
                Logger.d("Playlist ${location.parentFile} could not be saved:", e)
            } catch (e: Error) {
                Logger.d("Playlist ${location.parentFile} could not be saved:", e)
            } finally {
                try {
                    it.close()
                } catch (ex: Exception) {
                }
                isSaveNeeded = false
            }

It seems like everything possible should be caught. Yet my app crashes with: Fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/xenoamp/SCRATCH.m3u8: open failed: EACCES (Permission denied) at libcore.io.IoBridge.open(IoBridge.java:452) at java.io.FileOutputStream.(FileOutputStream.java:87) at java.io.FileOutputStream.(FileOutputStream.java:72) at pl.qus.io.XenoFileOutputStream.(SourceFile:36) at pl.qus.xenoamp.structures.PlaylistFiled.save(SourceFile:486) at pl.qus.xenoamp.xenoservice.XenoAmpService$onEventBackgroundThread$1.run(SourceFile:1304) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:224) at android.os.HandlerThread.run(HandlerThread.java:61) Caused by android.system.ErrnoException: open failed: EACCES (Permission denied) at libcore.io.Posix.open(Posix.java) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:438) at java.io.FileOutputStream.(FileOutputStream.java:87) at java.io.FileOutputStream.(FileOutputStream.java:72) at pl.qus.io.XenoFileOutputStream.(SourceFile:36) at pl.qus.xenoamp.structures.PlaylistFiled.save(SourceFile:486) at pl.qus.xenoamp.xenoservice.XenoAmpService$onEventBackgroundThread$1.run(SourceFile:1304) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:224) at android.os.HandlerThread.run(HandlerThread.java:61)

It started do happen all of the sudden (probably afer another update to Android ibraries). Any idea how to catch this exception? My app has all the required read/write permissions in manifest + requests them at runtime for >KitKat.

The error occurs on Android 4, 5 and 6.

ssuukk
  • 8,200
  • 7
  • 35
  • 47
  • 1
    if You develop for Builds since marshmallow, a runtime permission request is required..maybe that´s the problem? – Opiatefuchs Mar 15 '16 at 08:02
  • http://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android – Leonid Veremchuk Mar 15 '16 at 08:03
  • @Opiatefuchs I'm requesting this permission via ActivityCompat.requestPermissions, LeonidVeremchuk - no, that's not my case! – ssuukk Mar 15 '16 at 08:07
  • Like @Opiatefuchs said, what is your targetSdkVersion? WRITE_EXTERNAL_STORAGE is one of the permissions that need runtime approval on api level >=23. – JHH Mar 15 '16 at 08:10
  • My target SDK is 23 and I AM requesting this permission at runtime via ActivityCompat.requestPermissions – ssuukk Mar 15 '16 at 08:11
  • Also, what's with the colon syntax? `catch (e : Exception)`..? – JHH Mar 15 '16 at 08:15
  • Ooooh, sorry. That's Kotlin, not Java. – ssuukk Mar 15 '16 at 08:18
  • Sorry for asking after you already replied. Delay-glitch in my app. Have you tried recompiling the app with targetSdk 22 - and/or try the app on a pre-M device - just to confirm/rule out that the problem is related to RTP? RTP is a bit complex, so there are many places things could go wrong, but would be good to rule out other errors before diving into that can of worms. – JHH Mar 15 '16 at 08:19
  • I can check that, but still, shouldn't I be able to catch this exception regardless of sdk? – ssuukk Mar 15 '16 at 08:39
  • Of course. You're even catching Exception. This must be thrown somewhere else, strange thing is, FikeNotFoundException is a checked exception. – JHH Mar 15 '16 at 12:30

0 Answers0