]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6068 Fix NPE with views
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 24 Feb 2015 14:38:26 +0000 (15:38 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 24 Feb 2015 14:38:26 +0000 (15:38 +0100)
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultFileSystem.java

index 4d87aed7cd33be2de90618599747c85fe7d0f920..c7cd0ab6f1fdc108f9e96ff61728fb8983e1ee3c 100644 (file)
@@ -187,4 +187,12 @@ public class DefaultModuleFileSystemTest {
     verify(componentIndexer).execute(fs);
   }
 
+  @Test
+  public void should_not_fail_with_null_basedir() throws Exception {
+    // This is the case with views
+    when(initializer.baseDir()).thenReturn(null);
+    DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, ProjectDefinition.create(),
+      new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
+  }
+
 }
index a45fc16a0089fa7b9dbfb966c01c95bd91ec2193..77a3a99d6b170650598fd7f47e7a3a3015ab16ca 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.api.batch.fs.internal;
 
 import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 import org.sonar.api.batch.fs.FilePredicate;
 import org.sonar.api.batch.fs.FilePredicates;
@@ -63,8 +62,8 @@ public class DefaultFileSystem implements FileSystem {
   }
 
   protected DefaultFileSystem(File baseDir, Cache cache) {
-    Preconditions.checkNotNull(baseDir, "Base directory can't be null");
-    this.baseDir = baseDir.getAbsoluteFile();
+    // Basedir can be null with views
+    this.baseDir = baseDir != null ? baseDir.getAbsoluteFile() : new File(".");
     this.cache = cache;
     this.predicates = new DefaultFilePredicates(baseDir);
   }