]> source.dussan.org Git - sonarqube.git/commitdiff
merge 2.5-RC2: missing close of input stream
authorsimonbrandhof <simon.brandhof@gmail.com>
Mon, 10 Jan 2011 17:46:53 +0000 (18:46 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Mon, 10 Jan 2011 17:46:53 +0000 (18:46 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java

index 9d90f3e81b2e315fa6932cee296c7daac2b67715..6f2df32db492dba3809e87b7cbcaab1ed550770c 100644 (file)
@@ -88,18 +88,22 @@ public class ViolationPersisterDecorator implements Decorator {
    * @return checksums, never null
    */
   private List<String> getChecksums(SnapshotSource source) {
-    return source == null || source.getData() == null ? Collections.<String> emptyList() : getChecksums(source.getData());
+    return source == null || source.getData() == null ? Collections.<String>emptyList() : getChecksums(source.getData());
   }
 
   static List<String> getChecksums(String data) {
     List<String> result = Lists.newArrayList();
+    StringInputStream stream = new StringInputStream(data);
     try {
-      List<String> lines = IOUtils.readLines(new StringInputStream(data));
+      List<String> lines = IOUtils.readLines(stream);
       for (String line : lines) {
         result.add(getChecksum(line));
       }
     } catch (IOException e) {
       throw new SonarException("Unable to calculate checksums", e);
+      
+    } finally {
+      IOUtils.closeQuietly(stream);
     }
     return result;
   }
@@ -123,11 +127,11 @@ public class ViolationPersisterDecorator implements Decorator {
    * Search for past violation.
    */
   RuleFailureModel selectPastViolation(Violation violation, Multimap<Rule, RuleFailureModel> pastViolationsByRule) {
-    // skip violation, if there is no past violations with same rule
-    if (!pastViolationsByRule.containsKey(violation.getRule())) {
+    Collection<RuleFailureModel> pastViolations = pastViolationsByRule.get(violation.getRule());
+    if (pastViolations==null || pastViolations.isEmpty()) {
+      // skip violation, if there is no past violations with same rule
       return null;
     }
-    Collection<RuleFailureModel> pastViolations = pastViolationsByRule.get(violation.getRule());
     RuleFailureModel found = selectPastViolationUsingLine(violation, pastViolations);
     if (found == null) {
       found = selectPastViolationUsingChecksum(violation, pastViolations);