incorrect buffer filling and false EOF
See original GitHub issueWhen 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):
-
Gson gson = new Gson(); InputStream is = getResources().openRawResource(R.raw.graph); String json = (new Scanner(is)).useDelimiter("\\Z").next(); WeightedGraph<LocationDataPoint> TestGraph = gson.fromJson(json, new TypeToken<WeightedGraph<LocationDataPoint>>(){}.getType()); ```
- LocationDataPoint.java.txt
- WeightedGraph.java.txt
- Vertex.java.txt
- Graph.java.txt
- Edge.java.txt
The graph.json
was created by Gson, so it should be compatible with Gson…
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top GitHub Comments
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)
That is actually a good point; the documentation for
Scanner
says: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 usingScanner
? Please also try the latest Gson version.