@@ -63,6 +63,10 @@ public LDContext toLdContext(EvaluationContext evaluationContext) {
6363 return BuildSingleContext (evaluationContext .asMap (), finalKind , targetingKey );
6464 }
6565
66+ private boolean isNullOrEmpty (String value ) {
67+ return value == null || value .isEmpty ();
68+ }
69+
6670 /**
6771 * Get and validate a targeting key.
6872 *
@@ -74,7 +78,7 @@ private String getTargetingKey(String targetingKey, Value keyAsValue) {
7478 // Currently the targeting key will always have a value, but it can be empty.
7579 // So we want to treat an empty string as a not defined one. Later it could
7680 // become null, so we will need to check that.
77- if (!Objects . equals (targetingKey , "" ) && keyAsValue != null && keyAsValue .isString ()) {
81+ if (!isNullOrEmpty (targetingKey ) && keyAsValue != null && keyAsValue .isString ()) {
7882 // There is both a targeting key and a key. It will work, but probably
7983 // is not intentional.
8084 logger .warn ("EvaluationContext contained both a 'key' and 'targetingKey'." );
@@ -87,10 +91,10 @@ private String getTargetingKey(String targetingKey, Value keyAsValue) {
8791
8892 if (keyAsValue != null && keyAsValue .isString ()) {
8993 // Targeting key takes precedence over key, because targeting key is in the spec.
90- targetingKey = !Objects . equals (targetingKey , "" ) ? targetingKey : keyAsValue .asString ();
94+ targetingKey = !isNullOrEmpty (targetingKey ) ? targetingKey : keyAsValue .asString ();
9195 }
9296
93- if (targetingKey == null || targetingKey . isEmpty ( )) {
97+ if (isNullOrEmpty ( targetingKey )) {
9498 logger .error ("The EvaluationContext must contain either a 'targetingKey' or a 'key' and the type " + "must be a string." );
9599 }
96100 return targetingKey ;
0 commit comments