]> source.dussan.org Git - sonarqube.git/commitdiff
Improve quality
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 8 Feb 2016 10:28:38 +0000 (11:28 +0100)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 8 Feb 2016 10:28:38 +0000 (11:28 +0100)
server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java
sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java
sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java

index 07c72e8b8834954993b181ceda8bbd78bddad831..bceb9aa8c4a114cb5cdbe0e4b6f66324108423ad 100644 (file)
@@ -111,10 +111,7 @@ public class DefaultNotificationManager implements NotificationManager {
         alreadyLoggedDeserializationIssue = true;
       }
       return null;
-    } catch (IOException e) {
-      throw new SonarException(UNABLE_TO_READ_NOTIFICATION, e);
-
-    } catch (ClassNotFoundException e) {
+    } catch (IOException | ClassNotFoundException e) {
       throw new SonarException(UNABLE_TO_READ_NOTIFICATION, e);
     }
   }
index a850e8d4535f4db5327e220ebcef02f7033e0511..369ba2b5e91071dd48b5d5ac8fd33fc5ba729971 100644 (file)
@@ -124,8 +124,6 @@ public class HtmlReport implements Reporter {
   }
 
   public void writeToFile(IssuesReport report, File toFile, boolean complete) {
-    Writer writer = null;
-    FileOutputStream fos = null;
     try {
       freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
       freemarker.template.Configuration cfg = new freemarker.template.Configuration();
@@ -138,17 +136,14 @@ public class HtmlReport implements Reporter {
       root.put("complete", complete);
 
       Template template = cfg.getTemplate("issuesreport.ftl");
-      fos = new FileOutputStream(toFile);
-      writer = new OutputStreamWriter(fos, fs.encoding());
-      template.process(root, writer);
-      writer.flush();
 
+      try (FileOutputStream fos = new FileOutputStream(toFile); Writer writer = new OutputStreamWriter(fos, fs.encoding())) {
+        template.process(root, writer);
+        writer.flush();
+      }
     } catch (Exception e) {
       throw new IllegalStateException("Fail to generate HTML Issues Report to: " + toFile, e);
 
-    } finally {
-      IOUtils.closeQuietly(writer);
-      IOUtils.closeQuietly(fos);
     }
   }
 
@@ -173,18 +168,11 @@ public class HtmlReport implements Reporter {
   }
 
   private void copyDependency(File target, String filename) {
-    InputStream input = null;
-    OutputStream output = null;
-    try {
-      input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename);
-      output = new FileOutputStream(new File(target, filename));
+    try (InputStream input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename);
+      OutputStream output = new FileOutputStream(new File(target, filename))) {
       IOUtils.copy(input, output);
-
     } catch (IOException e) {
       throw new IllegalStateException("Fail to copy file " + filename + " to " + target, e);
-    } finally {
-      IOUtils.closeQuietly(input);
-      IOUtils.closeQuietly(output);
     }
   }
 
index 3be891628172b5e7aa3f72e1a9ccde79aebfc08d..83424ff4d5dcc321f5b2a061bb3beb6bd98e5ffe 100644 (file)
@@ -210,20 +210,20 @@ public class FeedFileSources extends BaseDataChange {
 
       return true;
     }
-  }
-
-  private static String ofNullableBytes(@Nullable byte[] shortBytes, @Nullable byte[] longBytes) {
-    byte[] result;
-    if (shortBytes == null) {
-      if (longBytes == null) {
-        return "";
+    
+    private static String ofNullableBytes(@Nullable byte[] shortBytes, @Nullable byte[] longBytes) {
+      byte[] result;
+      if (shortBytes == null) {
+        if (longBytes == null) {
+          return "";
+        } else {
+          result = longBytes;
+        }
       } else {
-        result = longBytes;
+        result = shortBytes;
       }
-    } else {
-      result = shortBytes;
+      return new String(result, StandardCharsets.UTF_8);
     }
-    return new String(result, StandardCharsets.UTF_8);
   }
 
   @Override