Browse Source

SONAR-12078 out of memory in CE if file has too many issues

tags/7.8
Simon Brandhof 5 years ago
parent
commit
baf8ce1ddc

+ 5
- 1
sonar-core/src/main/java/org/sonar/core/issue/tracking/BlockRecognizer.java View File

@@ -77,7 +77,7 @@ class BlockRecognizer<RAW extends Trackable, BASE extends Trackable> {
}

// Check if remaining number of lines exceeds threshold. It avoids processing too many combinations.
if (basesByLine.keySet().size() * rawsByLine.keySet().size() >= 250_000) {
if (isOverLimit(basesByLine.keySet().size(), rawsByLine.keySet().size())) {
return;
}

@@ -97,6 +97,10 @@ class BlockRecognizer<RAW extends Trackable, BASE extends Trackable> {
}
}

static boolean isOverLimit(long a, long b) {
return Math.multiplyExact(a, b) >= 250_000;
}

/**
* @param startLineA number of line from first version of text (numbering starts from 1)
* @param startLineB number of line from second version of text (numbering starts from 1)

+ 9
- 0
sonar-core/src/test/java/org/sonar/core/issue/tracking/BlockRecognizerTest.java View File

@@ -41,6 +41,15 @@ public class BlockRecognizerTest {
assertThat(compute(seq("bcde"), seq("abcde"), 3, 4)).isEqualTo(4);
}

@Test
public void isOverLimit() {
assertThat(BlockRecognizer.isOverLimit(20, 40)).isFalse();
assertThat(BlockRecognizer.isOverLimit(3, 100_000)).isTrue();

// multiplication of these two ints is higher than Integer.MAX_VALUE
assertThat(BlockRecognizer.isOverLimit(50_000, 60_000)).isTrue();
}

private int compute(LineHashSequence seqA, LineHashSequence seqB, int ai, int bi) {
return BlockRecognizer.lengthOfMaximalBlock(seqA, ai, seqB, bi);
}

Loading…
Cancel
Save