2020import com .google .api .core .ApiFutures ;
2121import com .google .common .collect .ImmutableMap ;
2222import com .google .firebase .ErrorCode ;
23+ import com .google .firebase .internal .Nullable ;
2324import com .google .firebase .remoteconfig .internal .TemplateResponse .ParameterValueResponse ;
2425import com .google .gson .Gson ;
2526import 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