Skip to content

Commit 486e841

Browse files
author
Athira M
committed
Handle empty context
1 parent 6ad97cd commit 486e841

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/com/google/firebase/remoteconfig/ServerTemplateImpl.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.api.core.ApiFutures;
2121
import com.google.common.collect.ImmutableMap;
2222
import com.google.firebase.ErrorCode;
23+
import com.google.firebase.internal.Nullable;
2324
import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterValueResponse;
2425
import com.google.gson.Gson;
2526
import com.google.gson.GsonBuilder;
@@ -78,10 +79,11 @@ private ServerTemplateImpl(Builder builder) {
7879
}
7980

8081
@Override
81-
public ServerConfig evaluate(KeysAndValues context) throws FirebaseRemoteConfigException {
82+
public ServerConfig evaluate(@Nullable KeysAndValues context)
83+
throws FirebaseRemoteConfigException {
8284
if (this.cache == null) {
8385
throw new FirebaseRemoteConfigException(ErrorCode.FAILED_PRECONDITION,
84-
"No Remote Config Server template in cache. Call load() before calling evaluate().");
86+
"No Remote Config Server template in cache. Call load() before calling evaluate().");
8587
}
8688

8789
Map<String, Value> configValues = new HashMap<>();
@@ -93,8 +95,11 @@ public ServerConfig evaluate(KeysAndValues context) throws FirebaseRemoteConfigE
9395
}
9496

9597
ConditionEvaluator conditionEvaluator = new ConditionEvaluator();
96-
ImmutableMap<String, Boolean> evaluatedCondition = ImmutableMap.copyOf(
97-
conditionEvaluator.evaluateConditions(cache.getServerConditions(), context));
98+
ImmutableMap<String, Boolean> evaluatedCondition =
99+
context != null && !cache.getServerConditions().isEmpty()
100+
? ImmutableMap.copyOf(
101+
conditionEvaluator.evaluateConditions(cache.getServerConditions(), context))
102+
: ImmutableMap.of();
98103
ImmutableMap<String, Parameter> parameters = ImmutableMap.copyOf(cache.getParameters());
99104
mergeDerivedConfigValues(evaluatedCondition, parameters, configValues);
100105

@@ -103,8 +108,7 @@ public ServerConfig evaluate(KeysAndValues context) throws FirebaseRemoteConfigE
103108

104109
@Override
105110
public ServerConfig evaluate() throws FirebaseRemoteConfigException {
106-
KeysAndValues context = new KeysAndValues.Builder().build();
107-
return evaluate(context);
111+
return evaluate(null);
108112
}
109113

110114
@Override

0 commit comments

Comments
 (0)