Skip to content

Commit

Permalink
Handle the fact that service loader instances are not thread safe #211.…
Browse files Browse the repository at this point in the history
… Also make `factory` safer.
  • Loading branch information
pdvrieze committed Jun 3, 2024
1 parent 0c3e1c2 commit bf4dcd5
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import java.io.*
import java.util.*
import javax.xml.transform.Result
import javax.xml.transform.Source
import kotlin.concurrent.Volatile
import kotlin.reflect.KClass
import nl.adaptivity.xmlutil.core.impl.multiplatform.Writer as MPWriter
import java.io.Writer as JavaIoWriter
Expand All @@ -49,16 +50,17 @@ public actual object XmlStreaming : XmlStreamingJavaCommon(), IXmlStreaming {

@Suppress("DEPRECATION")
@Deprecated("This functionality uses service loaders and isn't really needed. Will be removed in 1.0")
override val serializationLoader: ServiceLoader<SerializationProvider> by lazy {
override val serializationLoader: ServiceLoader<SerializationProvider> get() {
val service = SerializationProvider::class.java
ServiceLoader.load(service, service.classLoader)
return ServiceLoader.load(service, service.classLoader)
}

private val serviceLoader: ServiceLoader<XmlStreamingFactory> by lazy {
private val serviceLoader: ServiceLoader<XmlStreamingFactory> get() {
val service = XmlStreamingFactory::class.java
ServiceLoader.load(service, service.classLoader)
return ServiceLoader.load(service, service.classLoader)
}

@Volatile
private var _factory: XmlStreamingFactory? = null

private val factory: XmlStreamingFactory
Expand Down

0 comments on commit bf4dcd5

Please sign in to comment.