diff --git a/core-api/src/main/java/com/optimizely/ab/Optimizely.java b/core-api/src/main/java/com/optimizely/ab/Optimizely.java index 5fb996ac8..5e3ada52b 100644 --- a/core-api/src/main/java/com/optimizely/ab/Optimizely.java +++ b/core-api/src/main/java/com/optimizely/ab/Optimizely.java @@ -399,8 +399,10 @@ else if (userId == null) { logger.info("No feature flag was found for key \"{}\".", featureKey); return false; } + Map copiedAttributes = copyAttributes(attributes); FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes); + if (featureDecision.variation != null) { if (featureDecision.decisionSource.equals(FeatureDecision.DecisionSource.EXPERIMENT)) { sendImpression( @@ -647,7 +649,6 @@ else if (userId == null) { String variableValue = variable.getDefaultValue(); Map copiedAttributes = copyAttributes(attributes); - FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes); if (featureDecision.variation != null) { LiveVariableUsageInstance liveVariableUsageInstance = @@ -686,9 +687,10 @@ public List getEnabledFeatures(@Nonnull String userId, @Nonnull Map copiedAttributes = copyAttributes(attributes); for (FeatureFlag featureFlag : projectConfig.getFeatureFlags()){ String featureKey = featureFlag.getKey(); - if(isFeatureEnabled(featureKey, userId, attributes)) + if(isFeatureEnabled(featureKey, userId, copiedAttributes)) enabledFeaturesList.add(featureKey); } @@ -826,9 +828,9 @@ private boolean validateUserId(String userId) { } /** - * Helper function to check that the provided attributes are null if not than it returns a copy + * Helper method which makes separate copy of attributesMap variable and returns it * - * @param attributes the attributes map being validated + * @param attributes map to copy * @return copy of attributes */ private Map copyAttributes(Map attributes) {