Closed Bug 715312 Opened 8 years ago Closed 8 years ago

Robotium tests for Fennec Native do not close file input stream

Categories

(Testing :: Mochitest, defect)

x86
Linux
defect
Not set

Tracking

(Not tracked)

RESOLVED FIXED
mozilla12

People

(Reporter: kats, Assigned: jmaher)

Details

Attachments

(1 file, 1 obsolete file)

E/StrictMode(30310): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
E/StrictMode(30310): java.lang.Throwable: Explicit termination method 'close' not called
E/StrictMode(30310):    at dalvik.system.CloseGuard.open(CloseGuard.java:187)
E/StrictMode(30310):    at java.io.FileInputStream.<init>(FileInputStream.java:90)
E/StrictMode(30310):    at java.io.FileReader.<init>(FileReader.java:42)
E/StrictMode(30310):    at org.mozilla.fennec_kats.FennecNativeDriver.getFile(FennecNativeDriver.java:276)
E/StrictMode(30310):    at org.mozilla.fennec_kats.FennecNativeDriver.<init>(FennecNativeDriver.java:93)
E/StrictMode(30310):    at org.mozilla.fennec_kats.tests.testNewTab.setUp(testNewTab.java:62)
E/StrictMode(30310):    at junit.framework.TestCase.runBare(TestCase.java:125)
E/StrictMode(30310):    at junit.framework.TestResult$1.protect(TestResult.java:106)
E/StrictMode(30310):    at junit.framework.TestResult.runProtected(TestResult.java:124)
E/StrictMode(30310):    at junit.framework.TestResult.run(TestResult.java:109)
E/StrictMode(30310):    at junit.framework.TestCase.run(TestCase.java:118)
E/StrictMode(30310):    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
E/StrictMode(30310):    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
E/StrictMode(30310):    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:525)
E/StrictMode(30310):    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1547)
this should remove the error.
Assignee: nobody → jmaher
Status: NEW → ASSIGNED
Attachment #587016 - Flags: review?(bugmail.mozilla)
Comment on attachment 587016 [details] [diff] [review]
close file after opening it (1.0)

Review of attachment 587016 [details] [diff] [review]:
-----------------------------------------------------------------

::: build/mobile/robocop/FennecNativeDriver.java.in
@@ +276,5 @@
>        while ((line = br.readLine()) != null) {
>          text.append(line);
>          text.append('\n');
>        }
> +      fr.close();

It would be better to throw this fr.close() call into a finally block as explained at https://wiki.mozilla.org/Fennec/NativeUI/CodingStyle#Closing_resources so that it runs even if there are exceptions.

Also, you can close br instead of fr, as BufferedReader.close() will automatically close the underlying source reader. It doesn't make much of a difference either way but it seems like you explicitly broke out fr to be able to close it, which wasn't necessary.
Attachment #587016 - Flags: review?(bugmail.mozilla) → review-
ok, updated with a better flow for cleanup.
Attachment #587016 - Attachment is obsolete: true
Attachment #587097 - Flags: review?(bugmail.mozilla)
Attachment #587097 - Flags: review?(bugmail.mozilla) → review+
https://hg.mozilla.org/mozilla-central/rev/36e7f9692e36
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla12
You need to log in before you can comment on or make changes to this bug.