From 54682e3b4a7119632f642c2cde082eff4394112b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Mu=CC=88ller?= Date: Wed, 21 Aug 2024 14:14:22 +0200 Subject: [PATCH] Don't warn about replaced parts We need to override a Part from core in S2, which should be a valid use-case of the 'Replace' annotation. Instead of logging a warning, we now log an info. Fixes: SE-13940 --- .../java/sirius/kernel/di/PartRegistry.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/sirius/kernel/di/PartRegistry.java b/src/main/java/sirius/kernel/di/PartRegistry.java index ba39e2b2..9ed2fe2d 100644 --- a/src/main/java/sirius/kernel/di/PartRegistry.java +++ b/src/main/java/sirius/kernel/di/PartRegistry.java @@ -195,12 +195,11 @@ private void wireField(Object object, Field field) { @Override public void registerPart(Object part, Class... implementedInterfaces) { - String customizationName = Sirius.getCustomizationName(part.getClass().getName()); - if (!Sirius.isActiveCustomization(customizationName)) { + if (!Sirius.isActiveCustomization(Sirius.getCustomizationName(part.getClass().getName()))) { return; } Object successor = shadowMap.get(part.getClass()); - Class predecessor = determinePredecessor(part, customizationName); + Class predecessor = determinePredecessor(part); registerPart(part, implementedInterfaces, predecessor, successor); } @@ -225,7 +224,7 @@ private void registerPart(Object part, Class[] implementedInterfaces, Class determinePredecessor(Object part, String customizationName) { + private Class determinePredecessor(Object part) { Class predecessor = part.getClass().isAnnotationPresent(Replace.class) ? part.getClass().getAnnotation(Replace.class).value() : null; @@ -233,15 +232,10 @@ private Class determinePredecessor(Object part, String customizationName) { return null; } - if (customizationName == null) { - if (Sirius.isStartedAsTest() && part.getClass().getSimpleName().endsWith("Mock")) { - Injector.LOG.WARN("%s is mocked by %s", predecessor, part.getClass()); - } else { - Injector.LOG.WARN( - "@Replace should be only used within a customization. %s (%s) seems to be a base class!", - part, - part.getClass()); - } + if (Sirius.isStartedAsTest() && part.getClass().getSimpleName().endsWith("Mock")) { + Injector.LOG.WARN("%s is mocked by %s", predecessor, part.getClass()); + } else { + Injector.LOG.INFO("Part %s is replaced by %s using @Replace", predecessor, part.getClass()); } shadowMap.put(predecessor, part);