aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-12-03 13:38:45 +0000
committerGodin <mandrikov@gmail.com>2010-12-03 13:38:45 +0000
commit555287b5a0fd21e19f26afa7b9f683a244c39dad (patch)
treeab315da4dc22a489ff1f423616333a68c2e3461a
parentb24e8d9e7faed6b0cad3e43fa064820b578adae0 (diff)
downloadsonarqube-555287b5a0fd21e19f26afa7b9f683a244c39dad.tar.gz
sonarqube-555287b5a0fd21e19f26afa7b9f683a244c39dad.zip
SONAR-1450: Prevent NPE with Natural and VB plugins
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java3
2 files changed, 6 insertions, 0 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java
index c6a8a503256..30810cef199 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java
@@ -23,6 +23,9 @@ public class PastViolationsLoader implements BatchExtension {
public List<RuleFailureModel> getPastViolations(Resource resource) {
Snapshot snapshot = resourcePersister.getSnapshot(resource);
+ if (snapshot == null) { // TODO Godin: Prevent NPE with Natural and VB plugins
+ return Collections.emptyList();
+ }
Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, true);
if (previousLastSnapshot == null) {
return Collections.emptyList();
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java
index 5f7bc8e0b34..341b5107c4c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java
@@ -5,6 +5,7 @@ import org.junit.Test;
import org.sonar.api.database.model.RuleFailureModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Resource;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -34,6 +35,8 @@ public class PastViolationsLoaderTest extends AbstractDbUnitTestCase {
public void shouldGetPastResourceViolations() {
Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
doReturn(snapshot).when(resourcePersister)
+ .getSnapshot(any(Resource.class));
+ doReturn(snapshot).when(resourcePersister)
.getLastSnapshot(any(Snapshot.class), anyBoolean());
List<RuleFailureModel> violations = loader.getPastViolations(new JavaFile("file"));