4

I am working on an android application which has a sqlite database. After writing the code in my app related to database operation, I am getting below exception. Though my application doesn't stop/crash, but I want to know how to resolve this exception. I am not sure why this exception is occurring, but I suppose it has to do with sqlite operations. I have closed all streams, connections and cursors as recommended. Below is the stack trace:

689-698/? E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
        at dalvik.system.CloseGuard.open(CloseGuard.java:184)
        at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
        at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
        at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
        at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:57)
        at android.os.Binder.execTransact(Binder.java:446)
04-24 08:49:21.127      689-698/? E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
        at dalvik.system.CloseGuard.open(CloseGuard.java:184)
        at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
        at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
        at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
        at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:64)
        at android.os.Binder.execTransact(Binder.java:446)
04-24 08:49:21.129      689-698/? E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
        at dalvik.system.CloseGuard.open(CloseGuard.java:184)
        at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
        at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
        at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
        at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:71)
        at android.os.Binder.execTransact(Binder.java:446)

Could anyone please explain when does this exception occur and how to resolve it?

Sujit Devkar
  • 1,195
  • 3
  • 12
  • 22

1 Answers1

2

Like the log says:

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.

Explicit termination method 'close' not called

Note that the callstack shows where the resource was created. The message is printed when the resource is garbage-collected and it notices that it wasn't closed.

In your case, we can see that the resource is a ParcelFileDescriptor, and it was created automatically by the IBackupAgent$Stub.onTransact() method (i.e., when your BackupAgent is getting a call through binder).

The log should disappear if you make sure to close the ParcelFileDescriptors passed to your BackupAgent subclass.

Community
  • 1
  • 1
Snild Dolkow
  • 6,669
  • 3
  • 20
  • 32
  • But manual closing of the ParcelFileDescriptors is not done in Google example reference implementations for Android Backup. – JohnyTex Jan 04 '22 at 08:31
  • I think you will find useful https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html – bohdan_trotsenko Jan 10 '22 at 19:36