EOFException when reading QueueFile tape
JavaAndroidExceptionSquare TapeJava Problem Overview
I'm using Square's Tape library to queue uploads of data to the server.
The queue is stored in File in JSON format. When the app starts I init the queue and start uploading (i.e if on Wifi) However on some devices on users I'm seeing EOFException
with 'null'
message (logged in crashlytics).
The error occurs when creating a FileObjectQueue
object from an existing file - from the debug info gather the actual file is ~1MB.
Any ideas what's causing this or how to prevent it? - maybe I need to dust up on my java.io.
Edit: using Tape v1.2.1
Caused by: java.io.EOFException
at java.io.RandomAccessFile.readFully(RandomAccessFile.java:419)
at java.io.RandomAccessFile.readInt(RandomAccessFile.java:439)
at com.squareup.tape.QueueFile.readElement(:182)
at com.squareup.tape.QueueFile.readHeader(:162)
at com.squareup.tape.QueueFile.(:110)
at com.squareup.tape.FileObjectQueue.(:35)
at com.myapp.queue.MyUploadTaskQueue.create(:125)
Updated - Also seeing this error since upgrading to 1.2.2
Caused by: java.io.IOException: File is corrupt; length stored in header is 0.
at com.squareup.tape.QueueFile.readHeader(:165)
at com.squareup.tape.QueueFile.<init>(:117)
at com.squareup.tape.FileObjectQueue.<init>(:35)
Java Solutions
Solution 1 - Java
The EOFException shows that End Of File has been reached, that is, there are no more bytes to read. This exception is just another way to signal that there is nothing more to read, whereas other methods return a value, like -1. As you can see in your error stack trace, the methods throwing the exception are read methods; java.io.RandomAccessFile.readFully(RandomAccessFile.java:419)
and com.squareup.tape.QueueFile.readHeader(:165)
. As such, it can't be "prevented" unless you don't read all the bytes (which you typically want to), just catch it like so; catch(EOFException e) { /* ignore */ }
:)
https://docs.oracle.com/javase/7/docs/api/java/io/EOFException.html