Occasional NullPointerException when calling Gson.fromJson when converting to a TypedToken of type CopyOnWriteArraySet
See original GitHub issueGson version
2.8.9
Java / Android version
Multiple Android versions (23+)
Description
NullPointerException when calling Gson.fromJson when converting to a TypedToken of type CopyOnWriteArraySet. This crash is noticed on user devices but not reproducible locally while debugging.
Here is the code that is causing the null pointer.
CopyOnWriteArraySet<String> result;
Type type = new TypeToken<CopyOnWriteArraySet<String>>() {
}.getType();
Gson gson = new Gson();
result = gson.fromJson(json, type);
Exception stack trace
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Android Gson TypeToken NullpointerException - Stack Overflow
I am trying to parse a JSONArray using Gson. Whenever I am trying to initialize the object of class TypeToken. I see this...
Read more >NullPointerException on a simple collection - Google Groups
attempt to de-serialize with this (on android client): Type listType = new TypeToken<List<Catagory>>() {}.getType(); retObj = gson.fromJson(result, listType);
Read more >kalyandechiraju ( Kalyan Dechiraju ) - github record :)
Occasional NullPointerException when calling Gson.fromJson when converting to a TypedToken of type CopyOnWriteArraySet. Apparently the issue got fixed when ...
Read more >Returning error code is always 0 - Wilfred/Difftastic - IssueHint
Occasional NullPointerException when calling Gson.fromJson when converting to a TypedToken of type CopyOnWriteArraySet, 6, 2022-02-03, 2022-08-04.
Read more >JSON String to Java object using GSON
As the title said, here we want to convert a JSON string to a Java model by using GSON library. Basically we have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Apparently the issue has not resurfaced when we made the below two changes:
CopyOnWriteArraySet
. Instead casted in to anArrayList
and then pass it to constructor ofCopyOnWriteArraySet
.thanks! I’ll try it