Skip to content

Commit

Permalink
fix: Suppress logger when loading patches in PatchBundleLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 13, 2023
1 parent 4bc4b0d commit 72c9eb2
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ sealed class PatchBundleLoader private constructor(
}.filter {
Patch::class.java.isAssignableFrom(it)
}.mapNotNull { patchClass ->
patchClass.getInstance(logger)
patchClass.getInstance(logger, silent = true)
}.filter {
it.name != null
}.let { patches ->
Expand All @@ -60,21 +60,22 @@ sealed class PatchBundleLoader private constructor(
* Instantiates a [Patch]. If the class is a singleton, the INSTANCE field will be used.
*
* @param logger The [Logger] to use for logging.
* @param silent Whether to suppress logging.
* @return The instantiated [Patch] or `null` if the [Patch] could not be instantiated.
*/
internal fun Class<*>.getInstance(logger: Logger): Patch<*>? {
internal fun Class<*>.getInstance(logger: Logger, silent: Boolean = false): Patch<*>? {
return try {
getField("INSTANCE").get(null)
} catch (exception: NoSuchFieldException) {
logger.fine(
if (!silent) logger.fine(
"Patch class '${name}' has no INSTANCE field, therefor not a singleton. " +
"Will try to instantiate it."
)

try {
getDeclaredConstructor().newInstance()
} catch (exception: Exception) {
logger.severe(
if (!silent) logger.severe(
"Patch class '${name}' is not singleton and has no suitable constructor, " +
"therefor cannot be instantiated and will be ignored."
)
Expand Down

0 comments on commit 72c9eb2

Please sign in to comment.