58

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)
user207421
  • 305,947
  • 44
  • 307
  • 483
scottyab
  • 23,621
  • 16
  • 94
  • 105

1 Answers1

1

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

Adam Martinu
  • 253
  • 1
  • 11
  • Generally yes, but the Square's API states that if the queue is empty the peek method will return null and not throw an exception. We might expect that the library will handle the EOF exception internally. So I don't believe that EOF exception is normal here. – Mikhail Aug 09 '16 at 12:15