SLING-6450 - [HTL] Cannot retrieve "length" property for arrays of primitive types

* treated all arrays in a unitary way, irrespective of their type, for "length" retrieval

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1778282 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/CompileTimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/CompileTimeObjectModel.java
index af8bfc7..a01ad50 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/CompileTimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/CompileTimeObjectModel.java
@@ -16,6 +16,7 @@
  ******************************************************************************/
 package org.apache.sling.scripting.sightly.impl.compiler;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -281,11 +282,10 @@
     }
 
     private static Object getField(Object obj, String property) {
-        if (obj instanceof Object[] && "length".equals(property)) {
-            // Working around this limitation: http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getFields%28%29
-            return ((Object[]) obj).length;
-        }
         Class<?> cls = obj.getClass();
+        if (cls.isArray() && "length".equals(property)) {
+            return Array.getLength(obj);
+        }
         try {
             Field field = cls.getDeclaredField(property);
             return field.get(obj);