Skip to content

Commit

Permalink
[media.ccc.de] Fix NPE in search results if they contain a future talk
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiGr committed Dec 30, 2020
1 parent 3c8c8e7 commit ddf88b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ public InfoItemsPage<InfoItem> getInitialPage() {
|| getLinkHandler().getContentFilters().isEmpty()) {
JsonArray events = doc.getArray("events");
for (int i = 0; i < events.size(); i++) {
searchItems.commit(new MediaCCCStreamInfoItemExtractor(
events.getObject(i)));
// Ensure only uploaded talks are shown in the search results.
// If the release date is null, the talk has not been held or uploaded yet
// and no streams are going to be available anyway.
if (events.getObject(i).getString("release_date") != null) {
searchItems.commit(new MediaCCCStreamInfoItemExtractor(
events.getObject(i)));
}
}
}
return new InfoItemsPage<>(searchItems, null);
Expand All @@ -105,7 +110,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
try {
doc = JsonParser.object().from(site);
} catch (JsonParserException jpe) {
throw new ExtractionException("Could not parse json.", jpe);
throw new ExtractionException("Could not parse JSON.", jpe);
}
}
if (getLinkHandler().getContentFilters().contains(CONFERENCES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public String getTextualUploadDate() {
@Nullable
@Override
public DateWrapper getUploadDate() throws ParsingException {
return new DateWrapper(MediaCCCParsingHelper.parseDateFrom(getTextualUploadDate()));
final String date = getTextualUploadDate();
if (date == null) {
return null; // event is in the future...
}
return new DateWrapper(MediaCCCParsingHelper.parseDateFrom(date));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String getUrl(final String query, final List<String> contentFilter,
return "https://media.ccc.de/public/events/search?q="
+ URLEncoder.encode(query, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ParsingException("Could not create search string with querry: " + query, e);
throw new ParsingException("Could not create search string with query: " + query, e);
}
}
}

0 comments on commit ddf88b1

Please sign in to comment.