Skip to content

Commit 3fc5c64

Browse files
committed
Improve Long.hashCode to follow correct semantics.
PiperOrigin-RevId: 318960075 Change-Id: I11b65f96a10b1ddb6617d9b2ff3b1ed5bed506cc
1 parent adeefdc commit 3fc5c64

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

user/super/com/google/gwt/emul/java/lang/Long.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
*/
1616
package java.lang;
1717

18-
/**
19-
* Wraps a primitive <code>long</code> as an object.
20-
*/
18+
/** Wraps a primitive <code>long</code> as an object. */
2119
public final class Long extends Number implements Comparable<Long> {
2220

23-
/**
24-
* Use nested class to avoid clinit on outer.
25-
*/
21+
/** Use nested class to avoid clinit on outer. */
2622
static class BoxedValues {
2723
// Box values according to JLS - between -128 and 127
2824
static Long[] boxedValues = new Long[256];
@@ -56,7 +52,9 @@ public static Long decode(String s) throws NumberFormatException {
5652
}
5753

5854
public static int hashCode(long l) {
59-
return (int) l;
55+
int high = (int) (l >>> 32);
56+
int low = (int) l;
57+
return high ^ low;
6058
}
6159

6260
public static long highestOneBit(long i) {
@@ -109,15 +107,13 @@ public static long parseLong(String s, int radix) throws NumberFormatException {
109107
public static long reverse(long i) {
110108
int high = (int) (i >>> 32);
111109
int low = (int) i;
112-
return ((long) Integer.reverse(low) << 32)
113-
| (Integer.reverse(high) & 0xffffffffL);
110+
return ((long) Integer.reverse(low) << 32) | (Integer.reverse(high) & 0xffffffffL);
114111
}
115112

116113
public static long reverseBytes(long i) {
117114
int high = (int) (i >>> 32);
118115
int low = (int) i;
119-
return ((long) Integer.reverseBytes(low) << 32)
120-
| (Integer.reverseBytes(high) & 0xffffffffL);
116+
return ((long) Integer.reverseBytes(low) << 32) | (Integer.reverseBytes(high) & 0xffffffffL);
121117
}
122118

123119
public static long rotateLeft(long i, int distance) {

user/test/com/google/gwt/emultest/java/sql/SqlDateTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
package com.google.gwt.emultest.java.sql;
1717

1818
import com.google.gwt.junit.client.GWTTestCase;
19-
2019
import java.sql.Date;
2120

2221
/**
23-
* Tests {@link java.sql.Date}. We assume that the underlying
24-
* {@link java.util.Date} implementation is correct and concentrate only on the
25-
* differences between the two.
22+
* Tests {@link java.sql.Date}. We assume that the underlying {@link java.util.Date} implementation
23+
* is correct and concentrate only on the differences between the two.
2624
*/
27-
@SuppressWarnings("deprecation")
25+
@SuppressWarnings({"deprecation", "DoNotCall"})
2826
public class SqlDateTest extends GWTTestCase {
2927

3028
/**

0 commit comments

Comments
 (0)