aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-06-20 14:13:01 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-06-20 14:13:33 +0200
commit904b462c56317b1fb5a616534bd58aa9c9097d0b (patch)
treec0751ebf83b9e8d1f11a82ac5da0af9ff1f19287 /sonar-batch
parent845c4a64b09a2f5455e50862f757ed6b3eb32fff (diff)
downloadsonarqube-904b462c56317b1fb5a616534bd58aa9c9097d0b.tar.gz
sonarqube-904b462c56317b1fb5a616534bd58aa9c9097d0b.zip
Fix some quality flaws
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/Cache.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java11
3 files changed, 17 insertions, 7 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java b/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java
index 1cbe6af68ca..ff57e4c065d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/Cache.java
@@ -308,10 +308,14 @@ public class Cache<V extends Serializable> {
KeyFilter filter = new KeyFilter().append(KeyFilter.simpleTerm(firstKey)).append(KeyFilter.simpleTerm(secondKey));
return new ValueIterable<V>(iteratorExchange, filter);
} catch (Exception e) {
- throw new IllegalStateException("Fail to get values from cache " + name, e);
+ throw failToGetValues(e);
}
}
+ private IllegalStateException failToGetValues(Exception e) {
+ return new IllegalStateException("Fail to get values from cache " + name, e);
+ }
+
/**
* Lazy-loading values for a given key
*/
@@ -323,7 +327,7 @@ public class Cache<V extends Serializable> {
KeyFilter filter = new KeyFilter().append(KeyFilter.simpleTerm(firstKey));
return new ValueIterable<V>(iteratorExchange, filter);
} catch (Exception e) {
- throw new IllegalStateException("Fail to get values from cache " + name, e);
+ throw failToGetValues(e);
}
}
@@ -337,7 +341,7 @@ public class Cache<V extends Serializable> {
KeyFilter filter = new KeyFilter().append(KeyFilter.ALL);
return new ValueIterable<V>(iteratorExchange, filter);
} catch (Exception e) {
- throw new IllegalStateException("Fail to get values from cache " + name, e);
+ throw failToGetValues(e);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index f8e1dc601e3..c5dca91b146 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -186,6 +186,9 @@ public class DefaultIndex extends SonarIndex {
public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
// Reload resource so that effective key is populated
Resource indexedResource = getResource(resource);
+ if (indexedResource == null) {
+ throw new IllegalStateException("Resource is not indexed " + resource);
+ }
Iterable<Measure> unfiltered;
if (filter instanceof MeasuresFilters.MetricFilter) {
// optimization
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java
index a3d23bf4fde..46f569c4127 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/MeasureCache.java
@@ -25,6 +25,7 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.measures.RuleMeasure;
import org.sonar.api.resources.Resource;
+import org.sonar.api.technicaldebt.batch.Characteristic;
import org.sonar.api.technicaldebt.batch.TechnicalDebtModel;
import org.sonar.batch.index.Cache;
import org.sonar.batch.index.Cache.Entry;
@@ -77,12 +78,14 @@ public class MeasureCache implements BatchComponent {
sb.append(m.getMetricKey());
}
sb.append("|");
- if (m.getCharacteristic() != null) {
- sb.append(m.getCharacteristic().key());
+ Characteristic characteristic = m.getCharacteristic();
+ if (characteristic != null) {
+ sb.append(characteristic.key());
}
sb.append("|");
- if (m.getPersonId() != null) {
- sb.append(m.getPersonId());
+ Integer personId = m.getPersonId();
+ if (personId != null) {
+ sb.append(personId);
}
if (m instanceof RuleMeasure) {
sb.append("|");