Skip to content

Commit

Permalink
fix: issue open-feature#859 Fixed the logic to allow the tests to pas…
Browse files Browse the repository at this point in the history
…s by copying the passed in attributes

Signed-off-by: Adam Roberts <adam.roberts@collibra.com>
  • Loading branch information
ARobertsCollibra authored and Kavindu-Dodan committed Mar 22, 2024
1 parent 5c76410 commit 3683197
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/AbstractStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class AbstractStructure implements Structure {
}

AbstractStructure(Map<String, Value> attributes) {
this.attributes = attributes;
this.attributes = new HashMap<>(attributes);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/dev/openfeature/sdk/ImmutableContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ public ImmutableContext(Map<String, Value> attributes) {
*/
public ImmutableContext(String targetingKey, Map<String, Value> attributes) {
if (targetingKey != null && !targetingKey.trim().isEmpty()) {
attributes.put(TARGETING_KEY, new Value(targetingKey));
final Map<String, Value> actualAttribs = new HashMap<>(attributes);
actualAttribs.put(TARGETING_KEY, new Value(targetingKey));
this.structure = new ImmutableStructure(actualAttribs);
} else {
this.structure = new ImmutableStructure(attributes);
}
this.structure = new ImmutableStructure(attributes);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/openfeature/sdk/MutableContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public MutableContext(Map<String, Value> attributes) {
* @param attributes evaluation context attributes
*/
public MutableContext(String targetingKey, Map<String, Value> attributes) {
this.structure = new MutableStructure(attributes);
if (targetingKey != null && !targetingKey.trim().isEmpty()) {
attributes.put(TARGETING_KEY, new Value(targetingKey));
this.structure.attributes.put(TARGETING_KEY, new Value(targetingKey));
}
this.structure = new MutableStructure(attributes);
}

// override @Delegate methods so that we can use "add" methods and still return MutableContext, not Structure
Expand Down

0 comments on commit 3683197

Please sign in to comment.