Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java RandomAccessFile A resource was acquired at attached stack trace but never released

Tags:

java

android

OK this is a weird one.

I have an Android app which keeps a buffer of everything the user has typed on their keyboards in a file (buffered.log). Everything works perfectly, except in the weird situation where the clients install the app on somebodies phone that they have previously installed it on.

The app then throws this error:

03 20:20:34.678 22741-22749/com.menny.android.anysoftkeyboard 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:180)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:127)
at com.radicalninja.logger.FlushableCipherOutputStream.<init>(FlushableCipherOutputStream.java:50)
at com.radicalninja.logger.CipherUtils.flushableEncryptedBufferedWriter(CipherUtils.java:31)
at com.radicalninja.logger.FileWriter.openFileWriter(FileWriter.java:41)
at com.radicalninja.logger.FileWriter.<init>(FileWriter.java:30)
at com.radicalninja.logger.FileWriter.<init>(FileWriter.java:0)
at com.radicalninja.logger.LogManager.openExternalPublicStorage(LogManager.java:161)
at com.radicalninja.logger.LogManager.createFileWriter(LogManager.java:115)
at com.radicalninja.logger.LogFileController.openLogFile(LogFileController.java:18)
at com.radicalninja.logger.LogFileController.<init>(LogFileController.java:12)
at com.radicalninja.logger.Buffer.<init>(Buffer.java:0)
at com.radicalninja.logger.WordBuffer.<init>(WordBuffer.java:0)
at com.anysoftkeyboard.AnySoftKeyboard.onCreate(AnySoftKeyboard.java:328)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3808)
at android.app.ActivityThread.access$2100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1883)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

My question is: how can i check if a random access file was not closed properly, and close it before the app tries to create the same new RandomAccessFile the previous install was already using?

like image 963
Geordie Wicks Avatar asked Apr 15 '26 13:04

Geordie Wicks


1 Answers

OK this is my cludge fix for this issue:

Create new file with the same path when app first opens, and then delete it.

Seems to work, but doesn't seem very elegant

like image 110
Geordie Wicks Avatar answered Apr 17 '26 02:04

Geordie Wicks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!