diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2016-02-08 11:28:38 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2016-02-08 11:28:38 +0100 |
commit | 940fc6143ae975b2ea0e611121bab63e0df58948 (patch) | |
tree | 731f1761fe070369a77fc6fc6b3407c3a19181ed | |
parent | f73dbafaa20c7e4d14d6b4ac8aa72f01ed07e25b (diff) | |
download | sonarqube-940fc6143ae975b2ea0e611121bab63e0df58948.tar.gz sonarqube-940fc6143ae975b2ea0e611121bab63e0df58948.zip |
Improve quality
3 files changed, 18 insertions, 33 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java b/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java index 07c72e8b883..bceb9aa8c4a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java @@ -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); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java index a850e8d4535..369ba2b5e91 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java @@ -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); } } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java index 3be89162817..83424ff4d5d 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v50/FeedFileSources.java @@ -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 |