aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-10-05 18:02:31 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-10-05 18:44:44 +0200
commit59e1f8eca37d7a37e0837e437ab3e6eb38a7dfea (patch)
tree67d86a8824cd5904a5cf8179b52bf5803930590c /sonar-plugin-api
parent9bd6da57d295bec4f8d22d32c28cefd0032bceaa (diff)
downloadsonarqube-59e1f8eca37d7a37e0837e437ab3e6eb38a7dfea.tar.gz
sonarqube-59e1f8eca37d7a37e0837e437ab3e6eb38a7dfea.zip
SONAR-6847 Fix NPE when creating issues on root directory
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java9
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java7
2 files changed, 11 insertions, 5 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
index 5e1ebb651c2..c788f55ebd9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
@@ -21,6 +21,7 @@ package org.sonar.api.batch.fs.internal;
import java.io.File;
import java.nio.file.Path;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.utils.PathUtils;
@@ -67,7 +68,13 @@ public class DefaultInputDir extends DefaultInputComponent implements InputDir {
@Override
public String key() {
- return new StringBuilder().append(moduleKey).append(":").append(relativePath).toString();
+ StringBuilder sb = new StringBuilder().append(moduleKey).append(":");
+ if (StringUtils.isEmpty(relativePath)) {
+ sb.append("/");
+ } else {
+ sb.append(relativePath);
+ }
+ return sb.toString();
}
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
index fe72745346e..21e810aec94 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/Directory.java
@@ -19,14 +19,13 @@
*/
package org.sonar.api.resources;
+import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.WildcardPattern;
-import javax.annotation.CheckForNull;
-
/**
* @since 1.10
*/
@@ -140,8 +139,8 @@ public class Directory extends Resource {
public static Directory create(String relativePathFromBaseDir) {
Directory d = new Directory();
String normalizedPath = normalize(relativePathFromBaseDir);
- d.setKey(normalizedPath);
- d.setPath(normalizedPath);
+ d.setKey(normalizedPath == null ? SEPARATOR : normalizedPath);
+ d.setPath(normalizedPath == null ? "" : normalizedPath);
return d;
}