Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AssetManager$AssetInputStream.finalize() timed out after 10 seconds

We see an stream of the following crashes, all on Android 4.3 Samsung Galaxy s3

java.util.concurrent.TimeoutException: android.content.res.AssetManager$AssetInputStream.finalize() timed out after 10 seconds
       at android.content.res.AssetManager$AssetInputStream.close(AssetManager.java:559)
       at android.content.res.AssetManager$AssetInputStream.finalize(AssetManager.java:592)
       at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
       at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
       at java.lang.Thread.run(Thread.java:841)

Help anyone?

like image 763
Guy Avatar asked Dec 09 '14 15:12

Guy


1 Answers

Whenever you do read/write operation using StreamReader/StreamWriter classes, please make sure you are calling ioStream.close() inside first try{} block. Something like this:

    AssetManager AssetManager = mContext.getAssets();
    try {
        InputStream is = AssetManager.open("sample.json");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

Even If you have another try{} block under catch/finally {} block still it will throw above exception.

instead you can assign ioStream = null in catch/finally {} block.

catch (Exception ex) {
  // If ioStream object is outside the try block
  ioStream = null;
}
like image 193
RajeshVijayakumar Avatar answered Oct 20 '22 17:10

RajeshVijayakumar