Skip to content

Commit e9627a1

Browse files
committed
Deprecate ObjectUtils.hashCode for primitives in favor of JDK 8's hashCode methods
Issue: SPR-15395
1 parent 8e84fd0 commit e9627a1

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

spring-core/src/main/java/org/springframework/util/ObjectUtils.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public static int nullSafeHashCode(boolean[] array) {
447447
}
448448
int hash = INITIAL_HASH;
449449
for (boolean element : array) {
450-
hash = MULTIPLIER * hash + hashCode(element);
450+
hash = MULTIPLIER * hash + Boolean.hashCode(element);
451451
}
452452
return hash;
453453
}
@@ -492,7 +492,7 @@ public static int nullSafeHashCode(double[] array) {
492492
}
493493
int hash = INITIAL_HASH;
494494
for (double element : array) {
495-
hash = MULTIPLIER * hash + hashCode(element);
495+
hash = MULTIPLIER * hash + Double.hashCode(element);
496496
}
497497
return hash;
498498
}
@@ -507,7 +507,7 @@ public static int nullSafeHashCode(float[] array) {
507507
}
508508
int hash = INITIAL_HASH;
509509
for (float element : array) {
510-
hash = MULTIPLIER * hash + hashCode(element);
510+
hash = MULTIPLIER * hash + Float.hashCode(element);
511511
}
512512
return hash;
513513
}
@@ -537,7 +537,7 @@ public static int nullSafeHashCode(long[] array) {
537537
}
538538
int hash = INITIAL_HASH;
539539
for (long element : array) {
540-
hash = MULTIPLIER * hash + hashCode(element);
540+
hash = MULTIPLIER * hash + Long.hashCode(element);
541541
}
542542
return hash;
543543
}
@@ -558,35 +558,39 @@ public static int nullSafeHashCode(short[] array) {
558558
}
559559

560560
/**
561-
* Return the same value as {@link Boolean#hashCode()}}.
562-
* @see Boolean#hashCode()
561+
* Return the same value as {@link Boolean#hashCode(boolean)}}.
562+
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
563563
*/
564+
@Deprecated
564565
public static int hashCode(boolean bool) {
565-
return (bool ? 1231 : 1237);
566+
return Boolean.hashCode(bool);
566567
}
567568

568569
/**
569-
* Return the same value as {@link Double#hashCode()}}.
570-
* @see Double#hashCode()
570+
* Return the same value as {@link Double#hashCode(double)}}.
571+
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
571572
*/
573+
@Deprecated
572574
public static int hashCode(double dbl) {
573-
return hashCode(Double.doubleToLongBits(dbl));
575+
return Double.hashCode(dbl);
574576
}
575577

576578
/**
577-
* Return the same value as {@link Float#hashCode()}}.
578-
* @see Float#hashCode()
579+
* Return the same value as {@link Float#hashCode(float)}}.
580+
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
579581
*/
582+
@Deprecated
580583
public static int hashCode(float flt) {
581-
return Float.floatToIntBits(flt);
584+
return Float.hashCode(flt);
582585
}
583586

584587
/**
585-
* Return the same value as {@link Long#hashCode()}}.
586-
* @see Long#hashCode()
588+
* Return the same value as {@link Long#hashCode(long)}}.
589+
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
587590
*/
591+
@Deprecated
588592
public static int hashCode(long lng) {
589-
return (int) (lng ^ (lng >>> 32));
593+
return Long.hashCode(lng);
590594
}
591595

592596

spring-web/src/main/java/org/springframework/http/HttpRange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -321,7 +321,7 @@ public boolean equals(Object other) {
321321

322322
@Override
323323
public int hashCode() {
324-
return ObjectUtils.hashCode(this.suffixLength);
324+
return Long.hashCode(this.suffixLength);
325325
}
326326

327327
@Override

0 commit comments

Comments
 (0)