From c8d150808ca30044b753923efa30a46ee7a9f1db Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 10 Jan 2011 18:46:53 +0100 Subject: [PATCH] merge 2.5-RC2: missing close of input stream --- .../timemachine/ViolationPersisterDecorator.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java index 9d90f3e81b2..6f2df32db49 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java @@ -88,18 +88,22 @@ public class ViolationPersisterDecorator implements Decorator { * @return checksums, never null */ private List getChecksums(SnapshotSource source) { - return source == null || source.getData() == null ? Collections. emptyList() : getChecksums(source.getData()); + return source == null || source.getData() == null ? Collections.emptyList() : getChecksums(source.getData()); } static List getChecksums(String data) { List result = Lists.newArrayList(); + StringInputStream stream = new StringInputStream(data); try { - List lines = IOUtils.readLines(new StringInputStream(data)); + List 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 pastViolationsByRule) { - // skip violation, if there is no past violations with same rule - if (!pastViolationsByRule.containsKey(violation.getRule())) { + Collection pastViolations = pastViolationsByRule.get(violation.getRule()); + if (pastViolations==null || pastViolations.isEmpty()) { + // skip violation, if there is no past violations with same rule return null; } - Collection pastViolations = pastViolationsByRule.get(violation.getRule()); RuleFailureModel found = selectPastViolationUsingLine(violation, pastViolations); if (found == null) { found = selectPastViolationUsingChecksum(violation, pastViolations); -- 2.39.5