]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 25 Sep 2014 14:02:01 +0000 (16:02 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 25 Sep 2014 14:02:01 +0000 (16:02 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/internal/ValidatingRequest.java

index dc10991dc9823c013e97e4cf0b00bcb01fda63b4..237dc2399d5fd001ee0d9c0cc6df7f4da3549356 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform;
 
+import org.apache.commons.dbutils.DbUtils;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.sonar.api.ServerComponent;
 import org.sonar.core.persistence.DatabaseVersion;
@@ -71,6 +72,7 @@ public class BackendCleanup implements ServerComponent {
 
     } finally {
       dbSession.close();
+      DbUtils.closeQuietly(connection);
     }
   }
 
@@ -110,7 +112,7 @@ public class BackendCleanup implements ServerComponent {
 
       // Clear resource related tables
       for (String relatedTable : RESOURCE_RELATED_TABLES) {
-        deleteWhereResoureIdNotNull(relatedTable, connection);
+        deleteWhereResourceIdNotNull(relatedTable, connection);
       }
 
       deleteManualRules(connection);
@@ -120,16 +122,17 @@ public class BackendCleanup implements ServerComponent {
 
     } finally {
       dbSession.close();
+      DbUtils.closeQuietly(connection);
     }
   }
 
-  private void deleteWhereResoureIdNotNull(String tableName, Connection connection) {
+  private void deleteWhereResourceIdNotNull(String tableName, Connection connection) {
     try {
       connection.prepareStatement("DELETE FROM " + tableName + " WHERE resource_id IS NOT NULL").execute();
       // commit is useless on some databases
       connection.commit();
     } catch (SQLException e) {
-      // frequent use-case : the table does not exist
+      throw new IllegalStateException("Fail to delete table : " + tableName, e);
     }
   }
 
index 3e6ae8fbf7d467dc93f088d155428fb3a2d66f9d..8b5e6ed768e8d914949641aee7b4df7c69c80c8c 100644 (file)
@@ -131,6 +131,16 @@ public class IssueIndexMediumTest {
     assertThat(result.attribute("jira-issue-key")).isEqualTo("SONAR-1234");
   }
 
+  @Test(expected = IllegalStateException.class)
+  public void comments_field_is_not_available() throws Exception {
+    IssueDto issue = createIssue();
+    db.issueDao().insert(session, issue);
+    session.commit();
+
+    Issue result = index.getByKey(issue.getKey());
+    result.comments();
+  }
+
   @Test(expected = IllegalStateException.class)
   public void is_new_field_is_not_available() throws Exception {
     IssueDto issue = createIssue();
index 5836dd9914c8908972992e01d368cd88f979665c..1a77b6d0ca964efa7c336312c64af53cf8e28369 100644 (file)
@@ -101,7 +101,8 @@ public abstract class ValidatingRequest extends Request {
       LoggerFactory.getLogger(getClass()).error(message);
       throw new IllegalArgumentException(message);
     }
-    String value = StringUtils.defaultString(readParam(definition.deprecatedKey()), readParam(key));
+    String deprecatedKey = definition.deprecatedKey();
+    String value = deprecatedKey != null ? StringUtils.defaultString(readParam(deprecatedKey), readParam(key)) : readParam(key);
     value = StringUtils.defaultString(value, definition.defaultValue());
     if (value == null) {
       return null;