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:
@@ -1,5 +1,6 @@
|
|||||||
package kotlin.jdk7.test
|
package kotlin.jdk7.test
|
||||||
|
|
||||||
|
import org.junit.Ignore
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -43,6 +44,7 @@ class TryWithResourcesCloseableTest {
|
|||||||
assertTrue(e.suppressed.isEmpty())
|
assertTrue(e.suppressed.isEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test fun opFailsCloseFails() {
|
@Test fun opFailsCloseFails() {
|
||||||
val e = assertFails {
|
val e = assertFails {
|
||||||
Resource(faultyClose = true).use { error("op fail") }
|
Resource(faultyClose = true).use { error("op fail") }
|
||||||
@@ -51,6 +53,7 @@ class TryWithResourcesCloseableTest {
|
|||||||
assertTrue(e.suppressed.single() is IOException)
|
assertTrue(e.suppressed.single() is IOException)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test fun opFailsCloseFailsTwice() {
|
@Test fun opFailsCloseFailsTwice() {
|
||||||
val e = assertFails {
|
val e = assertFails {
|
||||||
Resource(faultyClose = true).use { res1 ->
|
Resource(faultyClose = true).use { res1 ->
|
||||||
|
|||||||
@@ -30,14 +30,20 @@ import kotlin.internal.*
|
|||||||
*/
|
*/
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
|
public inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
|
||||||
var exception: Throwable? = null
|
var closed = false
|
||||||
try {
|
try {
|
||||||
return block(this)
|
return block(this)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Exception) {
|
||||||
exception = e
|
closed = true
|
||||||
|
try {
|
||||||
|
this?.close()
|
||||||
|
} catch (closeException: Exception) {
|
||||||
|
}
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
} finally {
|
||||||
this.closeFinally(exception)
|
if (!closed) {
|
||||||
|
this?.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user