Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Okio use block is return unsafe #1187

Closed
yschimke opened this issue Jan 3, 2023 · 1 comment
Closed

Okio use block is return unsafe #1187

yschimke opened this issue Jan 3, 2023 · 1 comment

Comments

@yschimke
Copy link
Collaborator

yschimke commented Jan 3, 2023

A non local return from the inline function was skipping the close.

inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
var result: R? = null
var thrown: Throwable? = null
try {
result = block(this)
} catch (t: Throwable) {
thrown = t
}
try {
this?.close()
} catch (t: Throwable) {
if (thrown == null) thrown = t
else thrown.addSuppressed(t)
}
if (thrown != null) throw thrown
return result!!
}

inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {

See issue here https://github.com/square/okhttp/pull/7625/files#diff-c7abbac71d83fc93c0d3f76dbc609a0b64426b7a3f9a8548b1f1723b3e0a277c

@yschimke
Copy link
Collaborator Author

yschimke commented Jan 5, 2023

Closed in #1190

@yschimke yschimke closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant