From 1c21c372854d59d5b56484bd01de945892359225 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 1 Aug 2016 22:26:20 +0800 Subject: [PATCH] Avoid NPE --- source/net/filebot/media/MediaDetection.java | 7 ++----- source/net/filebot/subtitle/SubtitleUtilities.java | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 769a95ef..c6f9007e 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -730,11 +730,8 @@ public class MediaDetection { if (similarity >= 1) { return true; } else if (similarity >= 0.5 && e.getSeason() == null && e.getEpisode() != null && e.getSpecial() == null) { - for (SxE it : parseEpisodeNumber(f, false)) { - if (it.season < 0 && it.episode == e.getEpisode()) { - return true; - } - } + List numbers = parseEpisodeNumber(f, false); + return numbers != null && numbers.stream().anyMatch(it -> it.season < 0 && it.episode == e.getEpisode()); } return false; } diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index ac8e1b3a..6861aa9d 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; import java.util.function.Predicate; @@ -170,7 +171,7 @@ public final class SubtitleUtilities { if (searchBySeries) { // search for subtitles for the given files - List numbers = files.stream().flatMap(f -> parseEpisodeNumber(f, true).stream()).distinct().collect(toList()); + List numbers = files.stream().map(f -> parseEpisodeNumber(f, true)).filter(Objects::nonNull).flatMap(Collection::stream).distinct().collect(toList()); if (numbers.size() == 1) { episodeFilter = numbers.stream().map(sxe -> new int[] { sxe.season, sxe.episode }).toArray(int[][]::new); // season-and-episode filter