Skip to content

Commit

Permalink
fix: Delegate PatchBundleLoader by mutable set of patches
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 12, 2023
1 parent d49e4ee commit 9a109c1
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -28,12 +28,17 @@ typealias PatchClass = KClass<out Patch<*>>
*
* @param getBinaryClassNames A function that returns the binary names of all classes in a patch bundle.
* @param classLoader The [ClassLoader] to use for loading the classes.
* @param patchBundles A set of patches to initialize this instance with.
*/
sealed class PatchBundleLoader private constructor(
classLoader: ClassLoader,
patchBundles: Array<out File>,
getBinaryClassNames: (patchBundle: File) -> List<String>,
) : PatchSet by mutableSetOf() {
// This constructor parameter is unfortunately necessary,
// so that a reference to the mutable set is present in the constructor to be able to add patches to it.
// because the instance itself is a PatchSet, which is immutable, that is delegated by the parameter.
private val patchSet: MutableSet<Patch<*>> = mutableSetOf()
) : PatchSet by patchSet {
private val logger = Logger.getLogger(PatchBundleLoader::class.java.name)

init {
Expand All @@ -46,8 +51,7 @@ sealed class PatchBundleLoader private constructor(
}.filter {
it.name != null
}.let { patches ->
@Suppress("UNCHECKED_CAST")
(this as MutableSet<Patch<*>>).addAll(patches)
patchSet.addAll(patches)
}
}

Expand Down

0 comments on commit 9a109c1

Please sign in to comment.