This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/SLING-13092-emit-array-service-properties
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git

commit acc2c079b7aa67aa6d6dd2cb3a5a0b765218ca06
Author: Konrad Windszus <[email protected]>
AuthorDate: Mon Feb 2 18:42:19 2026 +0100

    SLING-13092 Emit service properties containing arrays properly
    
    Previously the default Java representation of arrays was used which
    doesn't expose the item's values.
---
 .../models/impl/ModelConfigurationPrinter.java     | 45 +++++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java 
b/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java
index b804530..8b60c1d 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelConfigurationPrinter.java
@@ -54,6 +54,39 @@ public class ModelConfigurationPrinter {
         this.adapterImplementations = adapterImplementations;
     }
 
+    /**
+     * Converts an arbitrary property value to its string representation.
+     * Properly handles arrays, nulls, and various types.
+     *
+     * @param value the property value to convert (can be null, array, or any 
object)
+     * @return a string representation of the value, or "null" if value is null
+     */
+    private String propertyToString(Object value) {
+        if (value == null) {
+            return "null";
+        }
+
+        // Handle arrays
+        if (value.getClass().isArray()) {
+            Object[] array = (Object[]) value;
+            if (array.length == 0) {
+                return "[]";
+            }
+            StringBuilder sb = new StringBuilder("[");
+            for (int i = 0; i < array.length; i++) {
+                if (i > 0) {
+                    sb.append(", ");
+                }
+                sb.append(array[i] != null ? array[i].toString() : "null");
+            }
+            sb.append("]");
+            return sb.toString();
+        }
+
+        // Handle all other types
+        return value.toString();
+    }
+
     public void printConfiguration(PrintWriter printWriter) {
 
         // injectors
@@ -153,15 +186,17 @@ public class ModelConfigurationPrinter {
                     
bundleContext.getServiceReferences(Servlet.class.getName(), 
EXPORT_SERVLET_FILTER);
             if (servlets != null) {
                 for (ServiceReference ref : servlets) {
-                    
printWriter.print(ref.getProperty(ModelPackageBundleListener.PROP_EXPORTER_SERVLET_CLASS));
+                    printWriter.print(
+                            
propertyToString(ref.getProperty(ModelPackageBundleListener.PROP_EXPORTER_SERVLET_CLASS)));
                     printWriter.print(" exports '");
-                    
printWriter.print(ref.getProperty("sling.servlet.resourceTypes"));
+                    
printWriter.print(propertyToString(ref.getProperty("sling.servlet.resourceTypes")));
                     printWriter.print("' with selector '");
-                    
printWriter.print(ref.getProperty("sling.servlet.selectors"));
+                    
printWriter.print(propertyToString(ref.getProperty("sling.servlet.selectors")));
                     printWriter.print("' and extension '");
-                    
printWriter.print(ref.getProperty("sling.servlet.extensions"));
+                    
printWriter.print(propertyToString(ref.getProperty("sling.servlet.extensions")));
                     printWriter.print("' with exporter '");
-                    
printWriter.print(ref.getProperty(ModelPackageBundleListener.PROP_EXPORTER_SERVLET_NAME));
+                    printWriter.print(
+                            
propertyToString(ref.getProperty(ModelPackageBundleListener.PROP_EXPORTER_SERVLET_NAME)));
                     printWriter.println("'");
                 }
             }

Reply via email to