]> source.dussan.org Git - sonarqube.git/commitdiff
fix a NPE when restoring a backup without node <alerts/>
authorsimonbrandhof <simon.brandhof@gmail.com>
Wed, 15 Dec 2010 11:02:17 +0000 (11:02 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Wed, 15 Dec 2010 11:02:17 +0000 (11:02 +0000)
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java

index 3149e62923c01ac6c92701cc4cf550312314982f..c1259bb32b42a954a102fc05e484e35b2b1c2a45 100644 (file)
@@ -92,18 +92,20 @@ public class ProfilesBackup implements Backupable {
   }
 
   private void importAlerts(RulesProfile profile) {
-    for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext();) {
-      Alert alert = ia.next();
-      Metric unMarshalledMetric = alert.getMetric();
-      String validKey = unMarshalledMetric.getKey();
-      Metric matchingMetricInDb = session.getSingleResult(Metric.class, "key", validKey);
-      if (matchingMetricInDb == null) {
-        LoggerFactory.getLogger(getClass()).error("Unable to find metric " + validKey);
-        ia.remove();
-        continue;
+    if (profile.getAlerts() != null) {
+      for (Iterator<Alert> ia = profile.getAlerts().iterator(); ia.hasNext();) {
+        Alert alert = ia.next();
+        Metric unMarshalledMetric = alert.getMetric();
+        String validKey = unMarshalledMetric.getKey();
+        Metric matchingMetricInDb = session.getSingleResult(Metric.class, "key", validKey);
+        if (matchingMetricInDb == null) {
+          LoggerFactory.getLogger(getClass()).error("Unable to find metric " + validKey);
+          ia.remove();
+          continue;
+        }
+        alert.setMetric(matchingMetricInDb);
+        alert.setRulesProfile(profile);
       }
-      alert.setMetric(matchingMetricInDb);
-      alert.setRulesProfile(profile);
     }
   }