EOFException when reading QueueFile tape

JavaAndroidExceptionSquare Tape

Java 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionscottyabView Question on Stackoverflow
Solution 1 - JavaAdam MartinuView Answer on Stackoverflow