diff --git a/pom.xml b/pom.xml index 1a3bdf4..79a5a90 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 2.0.18 - 5.3.2 + 5.4.0 6.1.0 2.3.0 6.1.0 @@ -67,11 +67,11 @@ 3.15.0 3.4.0 3.12.0 - 3.5.5 + 3.5.6 3.2.8 - 5.6.0.6792 - 0.8.14 - 0.10.0 + 5.7.0.6970 + 0.8.15 + 0.11.0 jacoco diff --git a/src/main/java/com/switcherapi/client/SwitcherContextBase.java b/src/main/java/com/switcherapi/client/SwitcherContextBase.java index 4f2fa7f..bee47d1 100644 --- a/src/main/java/com/switcherapi/client/SwitcherContextBase.java +++ b/src/main/java/com/switcherapi/client/SwitcherContextBase.java @@ -229,11 +229,13 @@ private static void validateContext() throws SwitcherContextException { * Register Switcher Keys based on context properties */ private static void registerSwitcherKeys() { - if (Objects.nonNull(contextBase)) { + final String contextLocation = contextStr(ContextKey.CONTEXT_LOCATION); + + if (Objects.nonNull(contextBase) && contextBase.getClass().getName().equals(contextLocation)) { registerSwitcherKey(contextBase.getClass().getFields()); } else { try { - final Class clazz = Class.forName(contextStr(ContextKey.CONTEXT_LOCATION)); + final Class clazz = Class.forName(contextLocation); registerSwitcherKey(clazz.getFields()); } catch(ClassNotFoundException e){ throw new SwitcherContextException(e.getMessage()); @@ -249,10 +251,14 @@ private static void registerSwitcherKeys() { private static void registerSwitcherKey(Field[] fields) { Set switcherKeys = new HashSet<>(); + SwitcherUtils.debug(logger, "Registering Switcher Keys from context: {}", contextStr(ContextKey.CONTEXT_LOCATION)); + SwitcherUtils.debug(logger, "Found {} fields in context class", fields.length); for (Field field : fields) { if (field.isAnnotationPresent(SwitcherKey.class)) { try { - switcherKeys.add(field.get(null).toString()); + final String keyFound = field.get(null).toString(); + SwitcherUtils.debug(logger, "Found Switcher Key: {} in field: {}", keyFound, field.getName()); + switcherKeys.add(keyFound); } catch (Exception e) { throw new SwitcherContextException( String.format("Error retrieving Switcher Key value from field %s", field.getName()));