From dc26c95b40c3d0f48ed539f91e53c1bff1dceec6 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sat, 12 Mar 2016 15:36:54 +0100 Subject: fixed possible NPE --- src/main/java/eu/siacs/conversations/utils/FileUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main') diff --git a/src/main/java/eu/siacs/conversations/utils/FileUtils.java b/src/main/java/eu/siacs/conversations/utils/FileUtils.java index 7c2a51c5..967c9b41 100644 --- a/src/main/java/eu/siacs/conversations/utils/FileUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/FileUtils.java @@ -153,6 +153,9 @@ public class FileUtils { * @return last extension or empty string */ public static String getLastExtension(final String filename) { + if (filename == null || filename.isEmpty()) { + return ""; + } final int lastDotPosition = filename.lastIndexOf('.'); final String lastPart = lastDotPosition != -1 ? filename.substring(lastDotPosition + 1) : ""; @@ -164,6 +167,9 @@ public class FileUtils { * @return second to last extension or empty string */ public static String getSecondToLastExtension(final String filename) { + if (filename == null || filename.isEmpty()) { + return ""; + } final int lastDotPosition = filename.lastIndexOf('.'); final int secondToLastDotPosition = filename.lastIndexOf('.', lastDotPosition - 1); final String secondToLastPart = secondToLastDotPosition != -1 ? -- cgit v1.2.3