xtern commented on a change in pull request #6819: IGNITE-12116 Support array 
as key for caches.
URL: https://github.com/apache/ignite/pull/6819#discussion_r319034968
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
 ##########
 @@ -5359,6 +5359,42 @@ public static void writeMap(ObjectOutput out, Map<?, ?> 
map) throws IOException
         return map;
     }
 
+
+    /**
+     * Calculate a hashCode for an array.
+     *
+     * @param obj Object.
+     */
+    public static int hashCode(Object obj) {
+        if (obj.getClass().isArray()) {
+            if (obj instanceof byte[])
+                return Arrays.hashCode((byte[])obj);
+            if (obj instanceof short[])
+                return Arrays.hashCode((short[])obj);
+            if (obj instanceof int[])
+                return Arrays.hashCode((int[])obj);
+            if (obj instanceof long[])
+                return Arrays.hashCode((long[])obj);
+            if (obj instanceof float[])
+                return Arrays.hashCode((float[])obj);
+            if (obj instanceof double[])
+                return Arrays.hashCode((double[])obj);
+            if (obj instanceof char[])
+                return Arrays.hashCode((char[])obj);
+            if (obj instanceof boolean[])
+                return Arrays.hashCode((boolean[])obj);
+
+            int result = 1;
+
+            for (Object element : (Object[])obj)
+                result = 31 * result + hashCode(element);
 
 Review comment:
   When we put null-key we get NPE with th problem description  
   "java.lang.NullPointerException: Ouch! Argument cannot be null: key"
   
   But when we put "new String[] {"c", null, "a"}" we get just NPE, and  I 
think we should at least explain the problem in the same way if this is the 
expected behavior.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to