Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in searchSubredditsByName #283

Open
zugaldia opened this issue Feb 2, 2019 · 1 comment
Open

NullPointerException in searchSubredditsByName #283

zugaldia opened this issue Feb 2, 2019 · 1 comment

Comments

@zugaldia
Copy link

zugaldia commented Feb 2, 2019

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!

@andehr
Copy link

andehr commented Apr 3, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants