JRAW
JRAW copied to clipboard
NullPointerException in searchSubredditsByName
I get a NPE when I try a query like the following, where client
is the configured instance of RedditClient
:
client.searchSubredditsByName(
SubredditSearchQuery.Builder("news")
.exact(false)
.includeNsfw(true)
.includeUnadvertisable(true).build()
The exception:
java.lang.NullPointerException: Null iconUrl
at net.dean.jraw.models.$AutoValue_SubredditSearchResult.<init>($AutoValue_SubredditSearchResult.java:27)
at net.dean.jraw.models.AutoValue_SubredditSearchResult.<init>(AutoValue_SubredditSearchResult.java:16)
at net.dean.jraw.models.AutoValue_SubredditSearchResult$MoshiJsonAdapter.fromJson(AutoValue_SubredditSearchResult.java:79)
at net.dean.jraw.models.AutoValue_SubredditSearchResult$MoshiJsonAdapter.fromJson(AutoValue_SubredditSearchResult.java:19)
at com.squareup.moshi.CollectionJsonAdapter.fromJson(CollectionJsonAdapter.java:76)
at com.squareup.moshi.CollectionJsonAdapter$2.fromJson(CollectionJsonAdapter.java:53)
at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
at net.dean.jraw.models.internal.AutoValue_SubredditSearchResultContainer$MoshiJsonAdapter.fromJson(AutoValue_SubredditSearchResultContainer.java:34)
at net.dean.jraw.models.internal.AutoValue_SubredditSearchResultContainer$MoshiJsonAdapter.fromJson(AutoValue_SubredditSearchResultContainer.java:20)
at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:41)
at net.dean.jraw.http.HttpResponse.deserializeWith(HttpResponse.kt:49)
at net.dean.jraw.RedditClient.searchSubredditsByName(RedditClient.kt:517)
...
This doesn't happen if I switch to .exact(true)
, changing the boolean values of the other SubredditSearchQuery
parameters doesn't affect the result (the NPE still happens).
Please let me know if there's anything else you need to troubleshoot the issue, loving the library otherwise!
This looks like the JSON deserialisation going wrong because a SubredditSearchResult
has a null iconUrl
. Perhaps you can use a workaround similar to mine; when I was finding OEmbed
elements in JSON responses with a null type
, I was getting this error.
You could adapt my workaround to deal with SubredditSearchResult
elements which have null iconUrls.