Skip to content

Refact: Copying attributes into new copiedAttributes variable #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 7, 2018
10 changes: 6 additions & 4 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,10 @@ else if (userId == null) {
logger.info("No feature flag was found for key \"{}\".", featureKey);
return false;
}

Map<String, ?> copiedAttributes = copyAttributes(attributes);
FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes);

if (featureDecision.variation != null) {
if (featureDecision.decisionSource.equals(FeatureDecision.DecisionSource.EXPERIMENT)) {
sendImpression(
Expand Down Expand Up @@ -647,7 +649,6 @@ else if (userId == null) {

String variableValue = variable.getDefaultValue();
Map<String, ?> copiedAttributes = copyAttributes(attributes);

FeatureDecision featureDecision = decisionService.getVariationForFeature(featureFlag, userId, copiedAttributes);
if (featureDecision.variation != null) {
LiveVariableUsageInstance liveVariableUsageInstance =
Expand Down Expand Up @@ -686,9 +687,10 @@ public List<String> getEnabledFeatures(@Nonnull String userId, @Nonnull Map<Stri
return enabledFeaturesList;
}

Map<String, ?> 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);
}

Expand Down Expand Up @@ -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<String, ?> copyAttributes(Map<String, ?> attributes) {
Expand Down