The following is valid, adapts to Closeable, used with use {..}
fun closeableMDC(props: Map<String, Any>): MDCCloseables {
props.forEach { (k, v) -> MDC.put(k, v.toString()) } // <-- false positive
return MDCCloseables(props.keys)
}
class MDCCloseables(private val keys: Set<String>) : Closeable {
override fun close() {
keys.forEach { MDC.remove(it) }
}
}
The following is valid, adapts to Closeable, used with
use {..}