diff --git a/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt b/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt index 300be50e1..272175c29 100644 --- a/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt +++ b/app/src/main/java/org/tasks/tasklist/SectionedDataSource.kt @@ -148,11 +148,14 @@ class SectionedDataSource constructor( sections.append(new.sectionedPosition, new) } - tailrec fun getNearestHeader(sectionedPosition: Int): Long = if (isHeader(sectionedPosition)) { - getHeaderValue(sectionedPosition) - } else { - getNearestHeader(sectionedPosition - 1) - } + tailrec fun getNearestHeader(sectionedPosition: Int): Long = + if (sectionedPosition < 0) { + -1 + } else if (isHeader(sectionedPosition)) { + getHeaderValue(sectionedPosition) + } else { + getNearestHeader(sectionedPosition - 1) + } fun getSectionValues(): List { val values = ArrayList()