aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-29 14:27:38 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-29 16:26:35 +0200
commitbabb50a4f143c312df1ba45955d3d589ecb2845f (patch)
tree6e447fa4fa342dfeecb5cecdc4d8e7bd5e9ad97c /sonar-core
parentebc7ebb5c530d1de13a79cb3f2d873af89f37efb (diff)
downloadsonarqube-babb50a4f143c312df1ba45955d3d589ecb2845f.tar.gz
sonarqube-babb50a4f143c312df1ba45955d3d589ecb2845f.zip
SONAR-4360 OufOfMemory error when too many issues
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java4
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java23
2 files changed, 22 insertions, 5 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java b/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java
index 33195157a6f..339cc935d7d 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java
@@ -19,6 +19,7 @@
*/
package org.sonar.core.component;
+import com.google.common.base.Strings;
import org.sonar.api.component.Component;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Resource;
@@ -36,6 +37,9 @@ public class ResourceComponent implements Component {
public ResourceComponent(Resource resource, @Nullable Snapshot snapshot) {
this.key = resource.getEffectiveKey();
+ if (Strings.isNullOrEmpty(key)) {
+ throw new IllegalArgumentException("Missing component key");
+ }
this.name = resource.getName();
this.longName = resource.getLongName();
this.qualifier = resource.getQualifier();
diff --git a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java
index e0e278b62b1..a3e87afd5b9 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/ResourceComponentTest.java
@@ -22,13 +22,18 @@ package org.sonar.core.component;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.File;
+import org.sonar.api.resources.Resource;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
public class ResourceComponentTest {
+
+ Resource file = new File("foo.c").setEffectiveKey("myproject:path/to/foo.c");
+
@Test
public void db_ids_should_be_optional() {
- ResourceComponent component = new ResourceComponent(new File("foo.c"), new Snapshot());
+ ResourceComponent component = new ResourceComponent(file, new Snapshot());
assertThat(component.snapshotId()).isNull();
assertThat(component.resourceId()).isNull();
@@ -39,7 +44,7 @@ public class ResourceComponentTest {
Snapshot snapshot = new Snapshot();
snapshot.setId(123);
snapshot.setResourceId(456);
- ResourceComponent component = new ResourceComponent(new File("foo.c"), snapshot);
+ ResourceComponent component = new ResourceComponent(file, snapshot);
assertThat(component.snapshotId()).isEqualTo(123);
assertThat(component.resourceId()).isEqualTo(456);
@@ -47,10 +52,18 @@ public class ResourceComponentTest {
@Test
public void should_use_effective_key() {
- File file = new File("foo.c");
- file.setEffectiveKey("myproject:path/to/foo.c");
ResourceComponent component = new ResourceComponent(file);
-
assertThat(component.key()).isEqualTo("myproject:path/to/foo.c");
}
+
+ @Test
+ public void effective_key_should_be_set() {
+ try {
+ File file = new File("foo.c");
+ new ResourceComponent(file);
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Missing component key");
+ }
+ }
}