diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-05-07 15:36:22 +0600 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-05-10 15:11:20 +0200 |
commit | 0def1fc0ee52cf74b2bed0e08c4b4b54dafdcfed (patch) | |
tree | 6095370f2d7c06bd4530011aae836ee9b6e850b7 /plugins | |
parent | b847d1c7fc7dbfc288652d4de8fa0473c7a27129 (diff) | |
download | sonarqube-0def1fc0ee52cf74b2bed0e08c4b4b54dafdcfed.tar.gz sonarqube-0def1fc0ee52cf74b2bed0e08c4b4b54dafdcfed.zip |
SONAR-3442 Fix possible ArrayIndexOutOfBoundsException
Diffstat (limited to 'plugins')
3 files changed, 14 insertions, 3 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingBlocksRecognizer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingBlocksRecognizer.java index ea4c1eee51f..c5a2666ae3a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingBlocksRecognizer.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingBlocksRecognizer.java @@ -40,6 +40,14 @@ public class ViolationTrackingBlocksRecognizer { this.cmp = new HashedSequenceComparator<StringText>(cmp); } + public boolean isValidLineInReference(int line) { + return (0 <= line) && (line < a.length()); + } + + public boolean isValidLineInSource(int line) { + return (0 <= line) && (line < b.length()); + } + /** * @param startA number of line from first version of text (numbering starts from 0) * @param startB number of line from second version of text (numbering starts from 0) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java index ee92393da35..fee56b16787 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java @@ -124,9 +124,9 @@ public class ViolationTrackingDecorator implements Decorator { List<ViolationPair> possiblePairs = Lists.newArrayList(); for (Violation newViolation : newViolations) { - if (newViolation.getLineId() != null) { + if (newViolation.getLineId() != null && rec.isValidLineInSource(newViolation.getLineId() - 1)) { for (RuleFailureModel pastViolation : pastViolationsByRule.get(newViolation.getRule().getId())) { - if (pastViolation.getLine() != null) { + if (pastViolation.getLine() != null && rec.isValidLineInReference(pastViolation.getLine() - 1)) { int weight = rec.computeLengthOfMaximalBlock(pastViolation.getLine() - 1, newViolation.getLineId() - 1); possiblePairs.add(new ViolationPair(pastViolation, newViolation, weight)); } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/tracking/HashedSequenceComparator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/tracking/HashedSequenceComparator.java index 0c312e1d147..5d82a5fa34d 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/tracking/HashedSequenceComparator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/tracking/HashedSequenceComparator.java @@ -31,7 +31,10 @@ public class HashedSequenceComparator<S extends Sequence> implements SequenceCom } public boolean equals(HashedSequence<S> a, int ai, HashedSequence<S> b, int bi) { - return a.hashes[ai] == b.hashes[bi] && cmp.equals(a.base, ai, b.base, bi); + if (a.hashes[ai] == b.hashes[bi]) { + return cmp.equals(a.base, ai, b.base, bi); + } + return false; } public int hash(HashedSequence<S> seq, int i) { |