diff --git a/src/main/java/org/spongepowered/asm/mixin/audit/ClassAlreadyLoadedException.java b/src/main/java/org/spongepowered/asm/mixin/audit/ClassAlreadyLoadedException.java new file mode 100644 index 00000000..bc0c2b58 --- /dev/null +++ b/src/main/java/org/spongepowered/asm/mixin/audit/ClassAlreadyLoadedException.java @@ -0,0 +1,53 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +/** + * + */ +package org.spongepowered.asm.mixin.audit; + +import org.spongepowered.asm.mixin.MixinException; + + +/** + * Exception raised when a class was loaded before mixins were able to be + * applied. + */ +public class ClassAlreadyLoadedException extends MixinException { + + private static final long serialVersionUID = 1L; + + public ClassAlreadyLoadedException(String message) { + super(message); + } + + public ClassAlreadyLoadedException(Throwable cause) { + super(cause); + } + + public ClassAlreadyLoadedException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java index d7e6b1fa..19d9aa00 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java @@ -51,6 +51,7 @@ import org.spongepowered.asm.mixin.MixinEnvironment; import org.spongepowered.asm.mixin.MixinEnvironment.Option; import org.spongepowered.asm.mixin.MixinEnvironment.Phase; import org.spongepowered.asm.mixin.MixinException; +import org.spongepowered.asm.mixin.audit.ClassAlreadyLoadedException; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler; import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler.ErrorAction; @@ -363,13 +364,22 @@ public class MixinTransformer extends TreeTransformer { for (MixinConfig config : this.configs) { unhandled.addAll(config.getUnhandledTargets()); } - - for (String nextClass : unhandled) { + + Logger auditLogger = LogManager.getLogger("mixin/audit"); + + for (String target : unhandled) { try { - this.logger.info("Force-loading class {}", nextClass); - Class.forName(nextClass, true, Launch.classLoader); + auditLogger.info("Force-loading class {}", target); + Class.forName(target, true, Launch.classLoader); } catch (ClassNotFoundException ex) { - throw new Error("Could not force-load " + nextClass); + auditLogger.error("Could not force-load " + target, ex); + } + } + + for (MixinConfig config : this.configs) { + for (String target : config.getUnhandledTargets()) { + ClassAlreadyLoadedException ex = new ClassAlreadyLoadedException(target + " was already classloaded"); + auditLogger.error("Could not force-load " + target, ex); } } }