Skip to content

Commit 05f20ca

Browse files
committed
Fix #973 Make sure all resources are closed
Make sure all FileStream and FileLock are closed using AutoClose pattern.
1 parent d8abadc commit 05f20ca

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

messaging/src/android/java/com/google/firebase/messaging/cpp/RegistrationIntentService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ public static void writeTokenToInternalStorage(Context context, String token) {
8787
// e.printStackTrace();
8888
// }
8989
try (FileOutputStream lockFileStream = context.openFileOutput(MessageWriter.LOCK_FILE, 0);
90-
// Acquire lock. This prevents the C++ code from consuming and clearing the file while we
91-
// append to it.
92-
FileLock lock = lockFileStream.getChannel().lock();
93-
FileOutputStream outputStream =
94-
context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND)) {
90+
// Acquire lock. This prevents the C++ code from consuming and clearing the file while we
91+
// append to it.
92+
FileLock lock = lockFileStream.getChannel().lock();
93+
FileOutputStream outputStream =
94+
context.openFileOutput(MessageWriter.STORAGE_FILE, Context.MODE_APPEND)) {
9595
// We send both the buffer length and the buffer itself so that we can potentially
9696
// process more than one event in the case where they get queued up.
9797
outputStream.write(sizeBuffer.array());
9898
outputStream.write(buffer);
9999
} catch (Exception e) {
100-
e.printStackTrace();
100+
e.printStackTrace();
101101
}
102102
}
103103

0 commit comments

Comments
 (0)