Mholloway has uploaded a new change for review. https://gerrit.wikimedia.org/r/319093
Change subject: Add null checks for classes with @Required fields ...................................................................... Add null checks for classes with @Required fields Added null checks as necessary (i.e., where not already present, as they were for most of the feed content). Additionally made the 'links' field in NewsItem @Nullable since I think this is possible (if unlikely) condition. Bug: T148897 Change-Id: Iab7bcb7bb6693cd22609d08ca9ca64d31191e7bb --- M app/src/main/java/org/wikipedia/feed/news/NewsItem.java M app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java M app/src/main/java/org/wikipedia/random/RandomSummaryService.java M app/src/main/java/org/wikipedia/server/restbase/RbPageService.java M app/src/main/java/org/wikipedia/zero/ZeroConfigClient.java 5 files changed, 18 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/93/319093/1 diff --git a/app/src/main/java/org/wikipedia/feed/news/NewsItem.java b/app/src/main/java/org/wikipedia/feed/news/NewsItem.java index e1e20b9..ad5fa04 100644 --- a/app/src/main/java/org/wikipedia/feed/news/NewsItem.java +++ b/app/src/main/java/org/wikipedia/feed/news/NewsItem.java @@ -17,14 +17,14 @@ public final class NewsItem { @SuppressWarnings("unused,NullableProblems") @Required @NonNull private String story; - @SuppressWarnings("unused,NullableProblems") @Required @NonNull private List<CardPageItem> links; + @SuppressWarnings("unused") @Nullable private List<CardPageItem> links; @NonNull public String story() { return story; } - @NonNull + @Nullable public List<CardPageItem> links() { return links; } diff --git a/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java b/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java index 8c0d407..dab6780 100644 --- a/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java +++ b/app/src/main/java/org/wikipedia/feed/news/NewsItemCard.java @@ -51,6 +51,7 @@ return removeImageCaption(StringUtil.fromHtml(newsItem.story())); } + @Nullable public List<CardPageItem> links() { return newsItem.links(); } diff --git a/app/src/main/java/org/wikipedia/random/RandomSummaryService.java b/app/src/main/java/org/wikipedia/random/RandomSummaryService.java index 72344cc..090ffb8 100644 --- a/app/src/main/java/org/wikipedia/random/RandomSummaryService.java +++ b/app/src/main/java/org/wikipedia/random/RandomSummaryService.java @@ -2,6 +2,8 @@ import android.support.annotation.NonNull; +import com.google.gson.JsonParseException; + import org.wikipedia.WikipediaApp; import org.wikipedia.dataclient.WikiSite; import org.wikipedia.dataclient.retrofit.RbCachedService; @@ -37,6 +39,9 @@ @Override public void onResponse(Call<CardPageItem> call, Response<CardPageItem> response) { if (response.isSuccessful()) { + if (response.body() == null) { + cb.onError(new JsonParseException("Bad response from server")); + } responseHeaderHandler.onHeaderCheck(response); CardPageItem item = response.body(); String namespace = item.namespace().toLegacyString(); diff --git a/app/src/main/java/org/wikipedia/server/restbase/RbPageService.java b/app/src/main/java/org/wikipedia/server/restbase/RbPageService.java index 563aff2..b37d201 100644 --- a/app/src/main/java/org/wikipedia/server/restbase/RbPageService.java +++ b/app/src/main/java/org/wikipedia/server/restbase/RbPageService.java @@ -1,5 +1,7 @@ package org.wikipedia.server.restbase; +import com.google.gson.JsonParseException; + import org.wikipedia.WikipediaApp; import org.wikipedia.dataclient.WikiSite; import org.wikipedia.dataclient.retrofit.RetrofitException; @@ -144,6 +146,9 @@ public void onResponse(Call<Map<String, RbDefinition.Usage[]>> call, Response<Map<String, RbDefinition.Usage[]>> response) { if (response.isSuccessful()) { + if (response.body() == null) { + cb.failure(new JsonParseException("Bad response from server")); + } responseHeaderHandler.onHeaderCheck(response); cb.success(new RbDefinition(response.body())); } else { diff --git a/app/src/main/java/org/wikipedia/zero/ZeroConfigClient.java b/app/src/main/java/org/wikipedia/zero/ZeroConfigClient.java index f86c153..9185345 100644 --- a/app/src/main/java/org/wikipedia/zero/ZeroConfigClient.java +++ b/app/src/main/java/org/wikipedia/zero/ZeroConfigClient.java @@ -3,6 +3,8 @@ import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; +import com.google.gson.JsonParseException; + import org.wikipedia.dataclient.WikiSite; import org.wikipedia.dataclient.retrofit.MwCachedService; import org.wikipedia.dataclient.retrofit.RetrofitException; @@ -58,6 +60,9 @@ public void onResponse(@NonNull Call<ZeroConfig> call, @NonNull Response<ZeroConfig> response) { if (response.isSuccessful()) { + if (response.body() == null) { + cb.failure(call, new JsonParseException("Bad response from server")); + } cb.success(call, response.body()); } else { cb.failure(call, RetrofitException.httpError(response, cachedService.retrofit())); -- To view, visit https://gerrit.wikimedia.org/r/319093 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iab7bcb7bb6693cd22609d08ca9ca64d31191e7bb Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Mholloway <mhollo...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits