Skip to content

Commit 3a091bd

Browse files
committed
Addressing Code Review (possible NPE and mistaken file at initialization).
1 parent 9471eed commit 3a091bd

File tree

1 file changed

+4
-4
lines changed
  • firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/metadata

1 file changed

+4
-4
lines changed

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/metadata/QueueFile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class QueueFile {
9595
* Data (Length bytes)
9696
* </pre>
9797
*/
98-
private File rafFile;
98+
private final File rafFile;
9999

100100
/**
101101
* Cached file length. Always a power of 2.
@@ -127,6 +127,7 @@ class QueueFile {
127127
* access a given file at a time.
128128
*/
129129
public QueueFile(File file) throws IOException {
130+
this.rafFile = file;
130131
if (!file.exists()) {
131132
initialize(file);
132133
}
@@ -221,19 +222,18 @@ private Element readElement(int position) throws IOException {
221222
private void initialize(File file) throws IOException {
222223
// Use a temp file so we don't leave a partially-initialized file.
223224
File tempFile = new File(file.getPath() + ".tmp");
224-
openAndExecute(raf -> {
225+
try (RandomAccessFile raf = open(tempFile)) {
225226
raf.setLength(INITIAL_LENGTH);
226227
raf.seek(0);
227228
byte[] headerBuffer = new byte[16];
228229
writeInts(headerBuffer, INITIAL_LENGTH, 0, 0, 0);
229230
raf.write(headerBuffer);
230-
});
231+
}
231232

232233
// A rename is atomic.
233234
if (!tempFile.renameTo(file)) {
234235
throw new IOException("Rename failed!");
235236
}
236-
this.rafFile = tempFile;
237237
}
238238

239239
/**

0 commit comments

Comments
 (0)