[java-decompiler] off-by-one in line mapping (EA-75719)

This commit is contained in:
Roman Shevchenko
2015-11-03 20:00:26 +01:00
parent 875f01f615
commit a7d476f680
2 changed files with 6 additions and 2 deletions
@@ -230,7 +230,7 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
private class ExactMatchLineNumbersMapping(private val mapping: IntArray) : LineNumbersMapping {
override fun bytecodeToSource(line: Int): Int {
for (i in 0..mapping.size step 2) {
for (i in mapping.indices step 2) {
if (mapping[i] == line) {
return mapping[i + 1]
}
@@ -239,7 +239,7 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
}
override fun sourceToBytecode(line: Int): Int {
for (i in 0..mapping.size step 2) {
for (i in mapping.indices step 2) {
if (mapping[i + 1] == line) {
return mapping[i]
}
@@ -104,7 +104,11 @@ class IdeaDecompilerTest : LightCodeInsightFixtureTestCase() {
val mapping = file.getUserData(LineNumbersMapping.LINE_NUMBERS_MAPPING_KEY)!!
assertEquals(11, mapping.bytecodeToSource(3))
assertEquals(3, mapping.sourceToBytecode(11))
assertEquals(23, mapping.bytecodeToSource(13))
assertEquals(13, mapping.sourceToBytecode(23))
assertEquals(-1, mapping.bytecodeToSource(1000))
assertEquals(-1, mapping.sourceToBytecode(1000))
}
}