Package for a RESOURCE_ID element is optional (default matches any package)

Test: locally
Bug: 294278500
Change-Id: I63f899aaea3510226d57cc2c57381cb198d6db27
diff --git a/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/configs/validators/ValidateUiElement.java b/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/configs/validators/ValidateUiElement.java
index 5fddd3f..48f2aa2 100644
--- a/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/configs/validators/ValidateUiElement.java
+++ b/libraries/app-helpers/spectatio/spectatio-util/src/android/platform/spectatio/configs/validators/ValidateUiElement.java
@@ -29,6 +29,7 @@
 import java.lang.reflect.Type;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -131,18 +132,14 @@
                 validateAndGetValue(JsonConfigConstants.VALUE, jsonObject, /*isOptional*/ false);
 
         // Package is not required for SCROLLABLE, CLICKABLE, TEXT, TEXT_CONTAINS and DESCRIPTION
-        String pkg = null;
 
-        // Package is optional for CLASS
-        if (JsonConfigConstants.CLASS.equals(type)) {
-            pkg = validateAndGetValue(JsonConfigConstants.PACKAGE, jsonObject, /*isOptional*/ true);
-        }
+        // Package is optional for CLASS and RESOURCE_ID
+        String pkg =
+                validateAndGetValue(JsonConfigConstants.PACKAGE, jsonObject, /*isOptional*/ true);
 
-        // Package is required for RESOURCE_ID
+        // For RESOURCE_ID, unspecified package should be treated as the empty string
         if (JsonConfigConstants.RESOURCE_ID.equals(type)) {
-            pkg =
-                    validateAndGetValue(
-                            JsonConfigConstants.PACKAGE, jsonObject, /*isOptional*/ false);
+            pkg = Objects.requireNonNullElse(pkg, "");
         }
 
         return new UiElement(type, value, pkg);