square/moshi

EOF exception at com.squareup.moshi.JsonUtf8Reader.nextNonWhitespace

mbalajee opened this issue · 2 comments

Moshi: 1.15.0

val bufferedSource = context.assets.open("file_name.json").source().buffer()
val users = moshi.adapter<List<User>>().fromJson(bufferedSource)

Result:

java.io.EOFException: End of input
at com.squareup.moshi.JsonUtf8Reader.nextNonWhitespace(JsonUtf8Reader.java:1146)
at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:339)
at com.squareup.moshi.JsonUtf8Reader.peek(JsonUtf8Reader.java:208)
at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:38)
at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:58)

What's the contents of the JSON? Can you provide a test case which reproduces the problem?

I was running a microbenchmark test in Android and the block that measures the performance is run multiple times. So the InputStream was consumed in the first run. I missed it completely. It is working fine after I changed the inputStream to a get() property.

Apologies for the confusion.