SLING-8580 - [feature-diff] exclude 'service.pid' and
'service.factoryPid' OSGi configurations keys from comparison, which
creates false positive diff
diff --git a/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java b/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
index 0590dc4..3210fa4 100644
--- a/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
+++ b/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
@@ -31,6 +31,10 @@
 
 public final class ConfigurationsComparator extends AbstractFeatureElementComparator {
 
+    private static final String SERVICE_PID_KEY = "service.pid";
+
+    private static final String SERVICE_FACTORY_PID_KEY = "service.factoryPid";
+
     public ConfigurationsComparator() {
         super("configurations");
     }
@@ -71,8 +75,9 @@
         while (previousKeys.hasMoreElements()) {
             String previousKey = previousKeys.nextElement();
 
+            // skip 'service.pid' and 'service.factoryPid' keys
             // no other way to check if a key was removed in a dictionary
-            if (hasKey(previousKey, currentProperties.keys())) {
+            if (!isReservedKey(previousKey) && hasKey(previousKey, currentProperties.keys())) {
                 Object previousValue = previousProperties.get(previousKey);
                 Object currentValue = currentProperties.get(previousKey);
 
@@ -86,11 +91,14 @@
         while (currentKeys.hasMoreElements()) {
             String currentKey = currentKeys.nextElement();
 
-            Object previousValue = previousProperties.get(currentKey);
-            Object currentValue = currentProperties.get(currentKey);
+            // skip 'service.pid' and 'service.factoryPid' keys
+            if (!isReservedKey(currentKey)) {
+                Object previousValue = previousProperties.get(currentKey);
+                Object currentValue = currentProperties.get(currentKey);
 
-            if (previousValue == null && currentValue != null) {
-                targetProperties.put(currentKey, currentValue);
+                if (previousValue == null && currentValue != null) {
+                    targetProperties.put(currentKey, currentValue);
+                }
             }
         }
 
@@ -99,6 +107,10 @@
         }
     }
 
+    private static boolean isReservedKey(String key) {
+        return SERVICE_PID_KEY.equals(key) || SERVICE_FACTORY_PID_KEY.equals(key);
+    }
+
     private static boolean areEquals(Object lhs, Object rhs) {
         if (lhs == rhs) {
             return true;