Closed Bug 738421 Opened 10 years ago Closed 10 years ago

java.lang.Throwable: Explicit termination method 'close' not called @


(Firefox for Android Graveyard :: General, defect)

Not set


(Not tracked)

Firefox 14


(Reporter: aaronmt, Assigned: wesj)




(1 file, 2 obsolete files)

E/StrictMode(10704): A resource was acquired at attached stack trace but never released. See for information on avoiding resource leaks.
E/StrictMode(10704): java.lang.Throwable: Explicit termination method 'close' not called
E/StrictMode(10704): 	at
E/StrictMode(10704): 	at<init>(
E/StrictMode(10704): 	at<init>(
E/StrictMode(10704): 	at org.mozilla.gecko.GeckoJarReader.getStream(
E/StrictMode(10704): 	at org.mozilla.gecko.Favicons$LoadFaviconTask.downloadFavicon(
E/StrictMode(10704): 	at org.mozilla.gecko.Favicons$LoadFaviconTask.doInBackground(
E/StrictMode(10704): 	at org.mozilla.gecko.Favicons$LoadFaviconTask.doInBackground(
E/StrictMode(10704): 	at android.os.AsyncTask$
E/StrictMode(10704): 	at java.util.concurrent.FutureTask$Sync.innerRun(
E/StrictMode(10704): 	at
E/StrictMode(10704): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(
E/StrictMode(10704): 	at java.util.concurrent.ThreadPoolExecutor$
E/StrictMode(10704): 	at

Tested via
Galaxy Nexus (Android 4.0.3)
Attached patch Patch (obsolete) — Splinter Review
Lets close this stuff! I'm not really sure what to do if this fails...
Assignee: nobody → wjohnston
Attachment #608492 - Flags: review?(sriram)
Comment on attachment 608492 [details] [diff] [review]

Review of attachment 608492 [details] [diff] [review]:

I am fine with the first part, except for indentation in 'catch' block.

The zip file part can better be like..

Zipfile zip;
try {
} catch {
} finally {
  if (zip != null)

r+ with these changes.
Attachment #608492 - Flags: review?(sriram) → review+
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 14
Attached patch Patch v2 (obsolete) — Splinter Review
So turned out that was a stupid patch I think. We can't close the stream or zip file until we've got the data we need. Basically that means we can't return a stream unless we copy the data into something like a ByteArrayStream or something. I figured at that point, its easier to just have the method return the BitmapDrawable we actually want.

If we ever have callers who want something more advanced, we can either expand or expose openZip, getStream, etc. and callers can be responsible for closing streams when they're done.

cpeterson found this, so I thought I'd let him tell me what else I'm doing wrong here.
Attachment #608492 - Attachment is obsolete: true
Attachment #608766 - Flags: review?(cpeterson)
Comment on attachment 608766 [details] [diff] [review]
Patch v2

Review of attachment 608766 [details] [diff] [review]:

::: mobile/android/base/
@@ +299,5 @@
> +                if (url.startsWith("jar:jar:")) {
> +                    image = GeckoJarReader.getBitmapDrawable(url);
> +                } else {
> +                    Log.e(LOGTAG, "Error downloading favicon", e);
> +                }

Why not check for "jar:jar:" URLs in doInBackground() before calling downloadFavicon()? Reading from the jar is not downloading.

You would need to move saveFaviconToDb() from downloadFavicon() to doInBackground() (so favicon from jars can be saved to the DB too). Saving a favicon to the DB does not seem an appropriate side effect of a method called `downloadFavicon()`.

::: mobile/android/base/
@@ +23,5 @@
>   */
>  public class GeckoJarReader {
>      static private String LOGTAG = "GeckoJarReader";
> +    static public BitmapDrawable getBitmapDrawable(String url) {

s/static public/public static/

Java coding style recommends that access modifiers (public) should proceed static modifier:

@@ +42,5 @@
> +                    bitmap = new BitmapDrawable(inputStream);
> +                    inputStream.close();
> +                }
> +                if (zip != null) {
> +                    zip.close();

If `new BitmapDrawable()` or `inputStream.close()` throw, then zip.close() won't be called.

@@ +52,5 @@
> +        return bitmap;
> +    }
> +
> +    static private ZipFile getZipFile(String url) throws IOException {

s/static private/private static/

@@ +58,5 @@
> +        File file = new File(fileUrl.getPath());
> +        return new ZipFile(file);
> +    }
> +
> +    static private InputStream getStream(ZipFile zip, Stack<String> jarUrls) throws IOException {

s/static private/private static/
Attachment #608766 - Flags: review?(cpeterson) → review-
Attached patch Patch v3Splinter Review
Attachment #608766 - Attachment is obsolete: true
Attachment #608803 - Flags: review?(cpeterson)
I saw another favicon error come by here for a local file:

I guess I should catch and smother that one too, but I'm leery to just catch and ignore all errors without logging their signature somehow.
Comment on attachment 608803 [details] [diff] [review]
Patch v3


Should this bug be nom'd for aurora?
Attachment #608803 - Flags: review?(cpeterson) → review+
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.