diff --git a/src/main/java/dev/openfeature/sdk/HookSupport.java b/src/main/java/dev/openfeature/sdk/HookSupport.java index 90f41b932..f0216b255 100644 --- a/src/main/java/dev/openfeature/sdk/HookSupport.java +++ b/src/main/java/dev/openfeature/sdk/HookSupport.java @@ -79,8 +79,9 @@ private EvaluationContext callBeforeHooks(FlagValueType flagValueType, HookConte EvaluationContext context = hookCtx.getCtx(); for (Hook hook : reversedHooks) { if (hook.supportsFlagValueType(flagValueType)) { - Optional optional = hook.before(hookCtx, hints); - if (optional != null && optional.isPresent()) { + Optional optional = Optional.ofNullable(hook.before(hookCtx, hints)) + .orElse(Optional.empty()); + if (optional.isPresent()) { context = context.merge(optional.get()); } } diff --git a/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java b/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java index d7f436c24..dd2d03ca1 100644 --- a/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java +++ b/src/test/java/dev/openfeature/sdk/testutils/TestFlagsUtils.java @@ -16,13 +16,13 @@ @UtilityClass public class TestFlagsUtils { - public static String BOOLEAN_FLAG_KEY = "boolean-flag"; - public static String STRING_FLAG_KEY = "string-flag"; - public static String INT_FLAG_KEY = "integer-flag"; - public static String FLOAT_FLAG_KEY = "float-flag"; - public static String OBJECT_FLAG_KEY = "object-flag"; - public static String CONTEXT_AWARE_FLAG_KEY = "context-aware"; - public static String WRONG_FLAG_KEY = "wrong-flag"; + public static final String BOOLEAN_FLAG_KEY = "boolean-flag"; + public static final String STRING_FLAG_KEY = "string-flag"; + public static final String INT_FLAG_KEY = "integer-flag"; + public static final String FLOAT_FLAG_KEY = "float-flag"; + public static final String OBJECT_FLAG_KEY = "object-flag"; + public static final String CONTEXT_AWARE_FLAG_KEY = "context-aware"; + public static final String WRONG_FLAG_KEY = "wrong-flag"; /** * Building flags for testing purposes.