Skip to content

Commit 27a1d7f

Browse files
fix: issue #859 Fixed the logic to allow the tests to pass by copying the passed in attributes
Signed-off-by: Adam Roberts <[email protected]>
1 parent bb5557e commit 27a1d7f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/main/java/dev/openfeature/sdk/AbstractStructure.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class AbstractStructure implements Structure {
1313
}
1414

1515
AbstractStructure(Map<String, Value> attributes) {
16-
this.attributes = attributes;
16+
this.attributes = new HashMap<>(attributes);
1717
}
1818

1919
/**

src/main/java/dev/openfeature/sdk/ImmutableContext.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public ImmutableContext(Map<String, Value> attributes) {
5252
*/
5353
public ImmutableContext(String targetingKey, Map<String, Value> attributes) {
5454
if (targetingKey != null && !targetingKey.trim().isEmpty()) {
55-
attributes.put(TARGETING_KEY, new Value(targetingKey));
55+
final Map<String, Value> actualAttribs = new HashMap<>(attributes);
56+
actualAttribs.put(TARGETING_KEY, new Value(targetingKey));
57+
this.structure = new ImmutableStructure(actualAttribs);
58+
} else {
59+
this.structure = new ImmutableStructure(attributes);
5660
}
57-
this.structure = new ImmutableStructure(attributes);
5861
}
5962

6063
/**

src/main/java/dev/openfeature/sdk/MutableContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public MutableContext(Map<String, Value> attributes) {
4242
* @param attributes evaluation context attributes
4343
*/
4444
public MutableContext(String targetingKey, Map<String, Value> attributes) {
45+
this.structure = new MutableStructure(attributes);
4546
if (targetingKey != null && !targetingKey.trim().isEmpty()) {
46-
attributes.put(TARGETING_KEY, new Value(targetingKey));
47+
this.structure.attributes.put(TARGETING_KEY, new Value(targetingKey));
4748
}
48-
this.structure = new MutableStructure(attributes);
4949
}
5050

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

0 commit comments

Comments
 (0)