Rollback Closeable.use implementation as it was in 1.0 in order not to call functions that were introduced in 1.1 from this inline function.
#KT-16026
This commit is contained in:
@@ -30,14 +30,20 @@ import kotlin.internal.*
|
||||
*/
|
||||
@InlineOnly
|
||||
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
|
||||
var exception: Throwable? = null
|
||||
var closed = false
|
||||
try {
|
||||
return block(this)
|
||||
} catch (e: Throwable) {
|
||||
exception = e
|
||||
} catch (e: Exception) {
|
||||
closed = true
|
||||
try {
|
||||
this?.close()
|
||||
} catch (closeException: Exception) {
|
||||
}
|
||||
throw e
|
||||
} finally {
|
||||
this.closeFinally(exception)
|
||||
if (!closed) {
|
||||
this?.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user