diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-12-14 10:24:59 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-12-14 10:24:59 +0100 |
commit | 43adad0053aca847f656346d1bc85e89f15d6ec0 (patch) | |
tree | 1283c6e21f7bd1ec888b8d149995a0ebe035d24b /sonar-plugin-api/src/main | |
parent | 1480dd77272d6531aa383e2a1a983bf1259a213e (diff) | |
download | sonarqube-43adad0053aca847f656346d1bc85e89f15d6ec0.tar.gz sonarqube-43adad0053aca847f656346d1bc85e89f15d6ec0.zip |
Fix quality flaws in PathUtils
Diffstat (limited to 'sonar-plugin-api/src/main')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/PathUtils.java | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/PathUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/PathUtils.java index 5ab9090dc01..94b1978a368 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/PathUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/PathUtils.java @@ -19,24 +19,25 @@ */ package org.sonar.api.utils; -import org.apache.commons.io.FilenameUtils; - -import javax.annotation.Nullable; import java.io.File; import java.io.IOException; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.apache.commons.io.FilenameUtils; /** * @since 4.0 */ public class PathUtils { - PathUtils() { + private PathUtils() { // only static methods } /** * Normalize path and replace file separators by forward slash */ + @CheckForNull public static String sanitize(@Nullable String path) { return FilenameUtils.normalize(path, true); } @@ -45,9 +46,13 @@ public class PathUtils { * Get canonical path and replace file separators by forward slash. This * method does not throw boring checked exception. */ + @CheckForNull public static String canonicalPath(@Nullable File file) { + if (file == null) { + return null; + } try { - return file != null ? FilenameUtils.separatorsToUnix(file.getCanonicalPath()) : null; + return FilenameUtils.separatorsToUnix(file.getCanonicalPath()); } catch (IOException e) { throw new IllegalStateException("Fail to get the canonical path of " + file.getAbsolutePath(), e); } |