question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

incorrect buffer filling and false EOF

See original GitHub issue

When reading the following graph.txt (originally .json), I get the following error:

com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 1025 path $.edges[3].weight
                      at com.google.gson.Gson.fromJson(Gson.java:898)
                      at com.google.gson.Gson.fromJson(Gson.java:853)
                      at com.google.gson.Gson.fromJson(Gson.java:802)

When I went down the rabbit hole I discovered that on java.lang.Thread.State: RUNNABLE at com.google.gson.stream.JsonReader.peek(JsonReader.java:453), when p=16, instead of returning with JsonToken.NUMBER, it continued to the next case and returned JsonToken.END_DOCUMENT.

For your convenience, I’ve attached dump from before and after the bug (col 1023,1024 and col 1025), and when I went WTF???. Gson just before crush (1023).txt Gson just before crush (1024).txt Gson just after crush (1025).txt Gson WTF - should have returned.txt

If you need, the following code was used (.java was replaced with .java.txt to get around GitHub exclusions):

The graph.json was created by Gson, so it should be compatible with Gson…

graph.txt

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
trusitshahcommented, Oct 23, 2018

I got a similar issue in my android app.

Caused by com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 225931 path $.data.polygons[220].paths[14].lat at com.google.gson.Gson.fromJson(Gson.java:898) at com.google.gson.Gson.fromJson(Gson.java:853) at com.google.gson.Gson.fromJson(Gson.java:802) at com.google.gson.Gson.fromJson(Gson.java:774)

0reactions
Marcono1234commented, Sep 18, 2022

This error can be avoided by passing InputStreamReader as a parameter to the fromJson method. In my case this error was caused by some lack of memory problems on some devices and the reader’s stream reaches its end before the actual end of your json.

That is actually a good point; the documentation for Scanner says:

If an invocation of the underlying readable’s Readable.read(CharBuffer) method throws an IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException() method.

So it could indeed be the case that the underlying stream threw an exception and Scanner silently considered it as end of stream. In case anyone is still experiencing this, could you please make sure you experience this even without using Scanner? Please also try the latest Gson version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - What could lead to the creation of false EOF in a GZip ...
My first port of call would be to check anywhere that you're using InputStream.read() - check that you're using the return value correctly, ......
Read more >
Bountysource
incorrect buffer filling and false EOF.
Read more >
Add `is_at_eof()` to `BufRead` trait - libs - Rust Internals
The documentation for fill_buf states that the internal buffer is filled "with more data from the inner reader if it is empty".
Read more >
feof - Manual - PHP
Returns true if the file pointer is at EOF or an error occurs (including ... PHP Warning: Wrong parameter count for feof() in...
Read more >
grep doesn't output until EOF if piped through cat
In the former case, the C library buffers output data in memory until either the buffer holding those data is filled or a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found