diff --git a/src/main/java/com/launchdarkly/openfeature/serverprovider/EvaluationContextConverter.java b/src/main/java/com/launchdarkly/openfeature/serverprovider/EvaluationContextConverter.java index ef356a1..2414f0f 100644 --- a/src/main/java/com/launchdarkly/openfeature/serverprovider/EvaluationContextConverter.java +++ b/src/main/java/com/launchdarkly/openfeature/serverprovider/EvaluationContextConverter.java @@ -36,7 +36,7 @@ public EvaluationContextConverter(LDLogger logger) { public LDContext toLdContext(EvaluationContext evaluationContext) { // Using the kind as a map here because getting a value from an immutable context that doesn't exist // throws. https://github.com/open-feature/java-sdk/pull/300 - Map attributes = evaluationContext.asMap(); + Map attributes = evaluationContext.asUnmodifiableMap(); Value kindAsValue = attributes.get("kind"); @@ -45,7 +45,7 @@ public LDContext toLdContext(EvaluationContext evaluationContext) { String kindString = kindAsValue.asString(); if (Objects.equals(kindString, "multi")) { // A multi-context. - return BuildMultiContext(evaluationContext); + return BuildMultiContext(attributes); } else { // Single context with specified kind. finalKind = kindString; @@ -60,7 +60,7 @@ public LDContext toLdContext(EvaluationContext evaluationContext) { targetingKey = getTargetingKey(targetingKey, keyAsValue); - return BuildSingleContext(evaluationContext.asMap(), finalKind, targetingKey); + return BuildSingleContext(attributes, finalKind, targetingKey); } private boolean isNullOrEmpty(String value) { @@ -103,13 +103,13 @@ private String getTargetingKey(String targetingKey, Value keyAsValue) { /** * Build a multi-context from an evaluation context. * - * @param evaluationContext The evaluation context containing multi-context information. + * @param contextAttributes The attributes of the evaluation context containing multi-context information. * @return The built context. */ - private LDContext BuildMultiContext(EvaluationContext evaluationContext) { + private LDContext BuildMultiContext(Map contextAttributes) { ContextMultiBuilder multiBuilder = LDContext.multiBuilder(); - evaluationContext.asMap().forEach((kind, attributes) -> { + contextAttributes.forEach((kind, attributes) -> { // Do not need to do anything for the kind key. if (Objects.equals(kind, "kind")) return; @@ -119,7 +119,7 @@ private LDContext BuildMultiContext(EvaluationContext evaluationContext) { return; } - Map attributesMap = attributes.asStructure().asMap(); + Map attributesMap = attributes.asStructure().asUnmodifiableMap(); Value keyAsValue = attributesMap.get("key"); Value targetingKeyAsValue = attributesMap.get("targetingKey"); String targetingKey = targetingKeyAsValue != null ? targetingKeyAsValue.asString() : "";