Files
kotlin-fork/idea/testData/android/lint/closeCursor.kt
T
Vyacheslav Gerasimov d0f1b81bfa Fixed bugs in Kotlin Android Lint CleanupDetector
#KT-14780 Fixed
#KT-14677 Fixed

(cherry picked from commit f591b4958e4a836d37d70c2ad8ff15e626c6342a)
2017-01-25 10:50:35 +03:00

37 lines
1.3 KiB
Kotlin
Vendored

// INSPECTION_CLASS: org.jetbrains.android.inspections.klint.AndroidLintInspectionToolProvider$AndroidKLintRecycleInspection
@file:Suppress("UNUSED_VARIABLE")
import android.app.Activity
import android.os.Bundle
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val cursor = contentResolver.<warning descr="This `Cursor` should be freed up after use with `#close()`">query</warning>(null, null, null, null, null)
// WARNING
contentResolver.<warning descr="This `Cursor` should be freed up after use with `#close()`">query</warning>(null, null, null, null, null)
// OK, closed in chained call
contentResolver.query(null, null, null, null, null).close()
// KT-14677: Kotlin Lint: "Missing recycle() calls" report cursor with `use()` call
val cursorUsed = contentResolver.query(null, null, null, null, null)
cursorUsed.use { }
// OK, used in chained call
contentResolver.query(null, null, null, null, null).use {
}
// KT-13372: Android Lint for Kotlin: false positive "Cursor should be freed" inside 'if' expression
if (true) {
val c = contentResolver.query(null, null, null, null, null)
c.close()
}
}
}