Skip to content

Commit 6ad5eca

Browse files
authored
Fix IndexOutOfBoundsException when processing redirects with invalid namespace
Problem: substring() was being called on redirect titles that didn't start with the expected template namespace, causing IndexOutOfBoundsException. Solution: Added filter to validate titles start with templateNamespace before substring operation. Invalid redirects are now logged as warnings and excluded from processing.
1 parent a4335e9 commit 6ad5eca

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

server/src/main/scala/org/dbpedia/extraction/server/stats/MappingStatsHolder.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,19 @@ object MappingStatsHolder {
5151
}
5252
}
5353

54-
val redirects = wikiStats.redirects.filterKeys(title => templateMappings.contains(title.substring(templateNamespace.length))).map(_.swap)
55-
54+
// Simple fix (commented out): just filter out invalid redirects silently
55+
// val redirects = wikiStats.redirects.filterKeys(title => title.startsWith(templateNamespace) && templateMappings.contains(title.substring(templateNamespace.length))).map(_.swap)
56+
57+
// Better fix: filter out invalid redirects with warning logging
58+
val redirects = wikiStats.redirects.filter { case (title, _) =>
59+
if (title.startsWith(templateNamespace)) {
60+
true
61+
} else {
62+
logger.warning(language.wikiCode + " redirect '" + title + "' does not start with '" + templateNamespace + "'")
63+
false
64+
}
65+
}.filterKeys(title => templateMappings.contains(title.substring(templateNamespace.length))).map(_.swap)
66+
5667
val holder = new MappingStatsHolder(mappings, statistics.toList, redirects, ignoreList)
5768

5869
logger.info("Updated "+language.wikiCode+" mapped statistics in "+prettyMillis(System.currentTimeMillis - millis))

0 commit comments

Comments
 (0)