diff --git a/android/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java b/android/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java index 5e01f61977fd..cc387b0cc593 100644 --- a/android/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java +++ b/android/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import java.io.ByteArrayOutputStream; import java.util.Random; import junit.framework.TestCase; @@ -66,6 +67,7 @@ public void testChar() { hasher.assertBytes(new byte[] {1, 2}); } + @J2ktIncompatible // no UTF_16LE support public void testString() { Random random = new Random(); for (int i = 0; i < 100; i++) { diff --git a/android/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java index 281ec4fef5a4..047e90eaa6f3 100644 --- a/android/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java @@ -16,6 +16,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.common.hash.HashTestUtils.RandomHasherAction; import java.io.ByteArrayOutputStream; @@ -34,6 +35,7 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { * and checks that their results are identical, no matter which newHasher version we used. */ public void testExhaustive() { + // TODO: b/484953702 - Split test so we can avoid StreamingVersion under J2KT. List hashers = ImmutableList.of( new StreamingVersion().newHasher(), @@ -93,6 +95,7 @@ private static void assertPutString(char[] chars) { assertEquals(h1.hash(), h2.hash()); } + @J2ktIncompatible // AbstractStreamingHasher static class StreamingVersion extends AbstractHashFunction { @Override public int bits() { diff --git a/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java b/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java index 13b96eef159f..1d6a1bd7c3ca 100644 --- a/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java +++ b/android/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java @@ -21,6 +21,7 @@ import static java.util.Collections.singleton; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.Iterables; import com.google.common.hash.HashTestUtils.RandomHasherAction; import java.io.ByteArrayOutputStream; @@ -38,6 +39,9 @@ * * @author Dimitris Andreou */ +// All tests use Sink, which uses the currently J2KT-incompatible AbstractStreamingHasher +// (Plus, testString in particular requires UTF_16LE support.) +@J2ktIncompatible @NullUnmarked public class AbstractStreamingHasherTest extends TestCase { public void testBytes() { diff --git a/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java b/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java index 23fd57761624..73e57e4b7e51 100644 --- a/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java +++ b/android/guava-tests/test/com/google/common/hash/BloomFilterTest.java @@ -29,6 +29,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableSet; import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray; @@ -54,6 +55,7 @@ * @author Dimitris Andreou */ @NullUnmarked +@J2ktIncompatible public class BloomFilterTest extends TestCase { private static final int NUM_PUTS = 100_000; private static final ThreadLocal random = diff --git a/android/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java index 5fcc3a0e4c57..91cd0d7497fe 100644 --- a/android/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java @@ -18,6 +18,7 @@ import static com.google.common.hash.Hashing.ChecksumType.CRC_32; import static com.google.common.truth.Truth.assertThat; +import com.google.common.annotations.J2ktIncompatible; import java.util.zip.Checksum; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -28,6 +29,7 @@ * @author Colin Decker */ @NullUnmarked +@J2ktIncompatible public class ChecksumHashFunctionTest extends TestCase { public void testCrc32_equalsChecksumValue() throws Exception { diff --git a/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java index 85c5cf84fbfc..2554f09a720d 100644 --- a/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java @@ -17,6 +17,7 @@ import static com.google.common.hash.Hashing.crc32c; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import java.util.Arrays; import java.util.Random; import junit.framework.TestCase; @@ -29,6 +30,7 @@ * @author Kurt Alfred Kluever */ @NullUnmarked +@J2ktIncompatible public class Crc32cHashFunctionTest extends TestCase { public void testEmpty() { assertCrc(0, new byte[0]); diff --git a/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java b/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java index c857c55acd3a..a6057e13f539 100644 --- a/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java +++ b/android/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java @@ -8,6 +8,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; @@ -21,6 +22,7 @@ * @author kylemaddison@google.com (Kyle Maddison) */ @NullUnmarked +@J2ktIncompatible public class Fingerprint2011Test extends TestCase { // Length of the sample string to produce diff --git a/android/guava-tests/test/com/google/common/hash/FunnelsTest.java b/android/guava-tests/test/com/google/common/hash/FunnelsTest.java index a065af02580c..6ec6ab1e00c2 100644 --- a/android/guava-tests/test/com/google/common/hash/FunnelsTest.java +++ b/android/guava-tests/test/com/google/common/hash/FunnelsTest.java @@ -32,6 +32,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.testing.EqualsTester; import java.io.OutputStream; import java.nio.ByteBuffer; @@ -45,6 +46,7 @@ * * @author Dimitris Andreou */ +@J2ktIncompatible @NullUnmarked public class FunnelsTest extends TestCase { public void testForBytes() { diff --git a/android/guava-tests/test/com/google/common/hash/HashCodeTest.java b/android/guava-tests/test/com/google/common/hash/HashCodeTest.java index 35c8865c2150..3da0cb7ef5e3 100644 --- a/android/guava-tests/test/com/google/common/hash/HashCodeTest.java +++ b/android/guava-tests/test/com/google/common/hash/HashCodeTest.java @@ -16,12 +16,13 @@ package com.google.common.hash; -import static com.google.common.hash.Hashing.sha1; +import static com.google.common.hash.Hashing.farmHashFingerprint64; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.US_ASCII; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.common.io.BaseEncoding; import com.google.common.testing.ClassSanityTester; @@ -178,16 +179,18 @@ public void testToString() { assertThat(base16().lowerCase().encode(data)).isEqualTo("7f8005ff0e"); } + @J2ktIncompatible // ClassSanityTester public void testHashCode_nulls() throws Exception { sanityTester().testNulls(); } + @J2ktIncompatible // ClassSanityTester public void testHashCode_equalsAndSerializable() throws Exception { sanityTester().testEqualsAndSerializable(); } public void testRoundTripHashCodeUsingBaseEncoding() { - HashCode hash1 = sha1().hashString("foo", US_ASCII); + HashCode hash1 = farmHashFingerprint64().hashString("foo", US_ASCII); HashCode hash2 = HashCode.fromBytes(BaseEncoding.base16().lowerCase().decode(hash1.toString())); assertEquals(hash1, hash2); } @@ -219,7 +222,7 @@ public void testObjectHashCodeWithSameLowOrderBytes() { } public void testRoundTripHashCodeUsingFromString() { - HashCode hash1 = sha1().hashString("foo", US_ASCII); + HashCode hash1 = farmHashFingerprint64().hashString("foo", US_ASCII); HashCode hash2 = HashCode.fromString(hash1.toString()); assertEquals(hash1, hash2); } @@ -238,7 +241,7 @@ public void testFromStringFailsWithInvalidHexChar() { } public void testFromStringFailsWithUpperCaseString() { - String string = sha1().hashString("foo", US_ASCII).toString().toUpperCase(); + String string = farmHashFingerprint64().hashString("foo", US_ASCII).toString().toUpperCase(); assertThrows(IllegalArgumentException.class, () -> HashCode.fromString(string)); } @@ -310,6 +313,7 @@ public void testWriteBytesToUndersizedArrayShortMaxLength() { assertThat(dest).isEqualTo(new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0x00}); } + @J2ktIncompatible // ClassSanityTester private static ClassSanityTester.FactoryMethodReturnValueTester sanityTester() { return new ClassSanityTester() .setDefault(byte[].class, new byte[] {1, 2, 3, 4}) @@ -357,7 +361,7 @@ private static void assertReadableBytes(HashCode hashCode) { private static class ExpectedHashCode { final byte[] bytes; final int asInt; - final Long asLong; // null means that asLong should throw an exception + final @Nullable Long asLong; // null means that asLong should throw an exception final String toString; ExpectedHashCode(byte[] bytes, int asInt, @Nullable Long asLong, String toString) { diff --git a/android/guava-tests/test/com/google/common/hash/HashFunctionEnum.java b/android/guava-tests/test/com/google/common/hash/HashFunctionEnum.java index 2258e84d86b6..7f1097d8a550 100644 --- a/android/guava-tests/test/com/google/common/hash/HashFunctionEnum.java +++ b/android/guava-tests/test/com/google/common/hash/HashFunctionEnum.java @@ -30,6 +30,7 @@ import static com.google.common.hash.Hashing.sha512; import static com.google.common.hash.Hashing.sipHash24; +import com.google.common.annotations.J2ktIncompatible; import org.jspecify.annotations.NullUnmarked; /** @@ -39,6 +40,7 @@ */ @SuppressWarnings("deprecation") // We still need to test our deprecated APIs. @NullUnmarked +@J2ktIncompatible enum HashFunctionEnum { ADLER32(adler32()), CRC32(crc32()), diff --git a/android/guava-tests/test/com/google/common/hash/HashTestUtils.java b/android/guava-tests/test/com/google/common/hash/HashTestUtils.java index 3fda291072d4..65be7c52415d 100644 --- a/android/guava-tests/test/com/google/common/hash/HashTestUtils.java +++ b/android/guava-tests/test/com/google/common/hash/HashTestUtils.java @@ -636,6 +636,7 @@ private static void assertHashLongEquivalence(HashFunction hashFunction, Random assertEquals(hashFunction.hashLong(l), hashFunction.newHasher().putLong(l).hash()); } + // TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these. private static final ImmutableSet CHARSETS = ImmutableSet.of(ISO_8859_1, US_ASCII, UTF_16, UTF_16BE, UTF_16LE, UTF_8); diff --git a/android/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java b/android/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java index d88d4b495d90..f4777fab0828 100644 --- a/android/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java +++ b/android/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.testing.NullPointerTester; import java.io.ByteArrayInputStream; import java.util.Arrays; @@ -33,6 +34,7 @@ * @author Qian Huang */ @NullUnmarked +@J2ktIncompatible public class HashingInputStreamTest extends TestCase { private Hasher hasher; private HashFunction hashFunction; diff --git a/android/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java b/android/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java index c6e096d74c4b..73929af03b33 100644 --- a/android/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java +++ b/android/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.testing.NullPointerTester; import java.io.ByteArrayOutputStream; import junit.framework.TestCase; @@ -31,6 +32,7 @@ * @author Zoe Piepmeier */ @NullUnmarked +@J2ktIncompatible public class HashingOutputStreamTest extends TestCase { private Hasher hasher; private HashFunction hashFunction; diff --git a/android/guava-tests/test/com/google/common/hash/HashingTest.java b/android/guava-tests/test/com/google/common/hash/HashingTest.java index 573ed7e4a8c3..60abf1d58363 100644 --- a/android/guava-tests/test/com/google/common/hash/HashingTest.java +++ b/android/guava-tests/test/com/google/common/hash/HashingTest.java @@ -23,6 +23,7 @@ import static java.util.Collections.shuffle; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableTable; @@ -53,6 +54,7 @@ */ @NullUnmarked public class HashingTest extends TestCase { + @J2ktIncompatible public void testMd5() { HashTestUtils.checkAvalanche(Hashing.md5(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.md5()); @@ -61,6 +63,7 @@ public void testMd5() { assertThat(Hashing.md5().toString()).isEqualTo("Hashing.md5()"); } + @J2ktIncompatible public void testSha1() { HashTestUtils.checkAvalanche(Hashing.sha1(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha1()); @@ -69,6 +72,7 @@ public void testSha1() { assertThat(Hashing.sha1().toString()).isEqualTo("Hashing.sha1()"); } + @J2ktIncompatible public void testSha256() { HashTestUtils.checkAvalanche(Hashing.sha256(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha256()); @@ -77,6 +81,7 @@ public void testSha256() { assertThat(Hashing.sha256().toString()).isEqualTo("Hashing.sha256()"); } + @J2ktIncompatible public void testSha384() { HashTestUtils.checkAvalanche(Hashing.sha384(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha384()); @@ -85,6 +90,7 @@ public void testSha384() { assertThat(Hashing.sha384().toString()).isEqualTo("Hashing.sha384()"); } + @J2ktIncompatible public void testSha512() { HashTestUtils.checkAvalanche(Hashing.sha512(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha512()); @@ -93,16 +99,19 @@ public void testSha512() { assertThat(Hashing.sha512().toString()).isEqualTo("Hashing.sha512()"); } + @J2ktIncompatible public void testCrc32() { HashTestUtils.assertInvariants(Hashing.crc32()); assertThat(Hashing.crc32().toString()).isEqualTo("Hashing.crc32()"); } + @J2ktIncompatible public void testAdler32() { HashTestUtils.assertInvariants(Hashing.adler32()); assertThat(Hashing.adler32().toString()).isEqualTo("Hashing.adler32()"); } + @J2ktIncompatible public void testMurmur3_128() { HashTestUtils.check2BitAvalanche(Hashing.murmur3_128(), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.murmur3_128(), 250, 0.17); @@ -112,6 +121,7 @@ public void testMurmur3_128() { assertThat(Hashing.murmur3_128().toString()).isEqualTo("Hashing.murmur3_128(0)"); } + @J2ktIncompatible public void testMurmur3_32() { HashTestUtils.check2BitAvalanche(Hashing.murmur3_32(), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.murmur3_32(), 250, 0.17); @@ -121,6 +131,7 @@ public void testMurmur3_32() { assertThat(Hashing.murmur3_32().toString()).isEqualTo("Hashing.murmur3_32(0)"); } + @J2ktIncompatible public void testSipHash24() { HashTestUtils.check2BitAvalanche(Hashing.sipHash24(), 250, 0.14); HashTestUtils.checkAvalanche(Hashing.sipHash24(), 250, 0.10); @@ -131,6 +142,7 @@ public void testSipHash24() { .isEqualTo("Hashing.sipHash24(506097522914230528, 1084818905618843912)"); } + @J2ktIncompatible public void testFingerprint2011() { HashTestUtils.check2BitAvalanche(Hashing.fingerprint2011(), 100, 0.4); HashTestUtils.checkAvalanche(Hashing.fingerprint2011(), 100, 0.4); @@ -141,6 +153,7 @@ public void testFingerprint2011() { } @AndroidIncompatible // slow TODO(cpovirk): Maybe just reduce iterations under Android. + @J2ktIncompatible public void testGoodFastHash() { for (int i = 1; i < 200; i += 17) { HashFunction hasher = Hashing.goodFastHash(i); @@ -150,6 +163,7 @@ public void testGoodFastHash() { } // goodFastHash(32) uses Murmur3_32. Use the same epsilon bounds. + @J2ktIncompatible public void testGoodFastHash32() { HashTestUtils.check2BitAvalanche(Hashing.goodFastHash(32), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.goodFastHash(32), 250, 0.17); @@ -159,6 +173,7 @@ public void testGoodFastHash32() { } // goodFastHash(128) uses Murmur3_128. Use the same epsilon bounds. + @J2ktIncompatible public void testGoodFastHash128() { HashTestUtils.check2BitAvalanche(Hashing.goodFastHash(128), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.goodFastHash(128), 500, 0.17); @@ -168,6 +183,7 @@ public void testGoodFastHash128() { } // goodFastHash(256) uses Murmur3_128. Use the same epsilon bounds. + @J2ktIncompatible public void testGoodFastHash256() { HashTestUtils.check2BitAvalanche(Hashing.goodFastHash(256), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.goodFastHash(256), 500, 0.17); @@ -176,6 +192,7 @@ public void testGoodFastHash256() { HashTestUtils.assertInvariants(Hashing.goodFastHash(256)); } + @J2ktIncompatible public void testConsistentHash_correctness() { long[] interestingValues = {-1, 0, 1, 2, Long.MAX_VALUE, Long.MIN_VALUE}; for (long h : interestingValues) { @@ -187,6 +204,7 @@ public void testConsistentHash_correctness() { } } + @J2ktIncompatible private void checkConsistentHashCorrectness(long hashCode) { int last = 0; for (int shards = 1; shards <= 100000; shards++) { @@ -198,6 +216,7 @@ private void checkConsistentHashCorrectness(long hashCode) { } } + @J2ktIncompatible public void testConsistentHash_probabilities() { AtomicLongMap map = AtomicLongMap.create(); Random r = new Random(9); @@ -210,6 +229,7 @@ public void testConsistentHash_probabilities() { } } + @J2ktIncompatible private void countRemaps(long h, AtomicLongMap map) { int last = 0; for (int shards = 2; shards <= MAX_SHARDS; shards++) { @@ -224,16 +244,19 @@ private void countRemaps(long h, AtomicLongMap map) { private static final int ITERS = 10000; private static final int MAX_SHARDS = 500; + @J2ktIncompatible public void testConsistentHash_outOfRange() { assertThrows(IllegalArgumentException.class, () -> Hashing.consistentHash(5L, 0)); } + @J2ktIncompatible public void testConsistentHash_ofHashCode() { checkSameResult(HashCode.fromLong(1), 1); checkSameResult(HashCode.fromLong(0x9999999999999999L), 0x9999999999999999L); checkSameResult(HashCode.fromInt(0x99999999), 0x0000000099999999L); } + @J2ktIncompatible public void checkSameResult(HashCode hashCode, long equivLong) { assertEquals(Hashing.consistentHash(equivLong, 5555), Hashing.consistentHash(hashCode, 5555)); } @@ -242,6 +265,7 @@ public void checkSameResult(HashCode hashCode, long equivLong) { * Check a few "golden" values to see that implementations across languages are equivalent. * */ + @J2ktIncompatible public void testConsistentHash_linearCongruentialGeneratorCompatibility() { int[] golden100 = { 0, 55, 62, 8, 45, 59, 86, 97, 82, 59, @@ -261,12 +285,14 @@ public void testConsistentHash_linearCongruentialGeneratorCompatibility() { private static final double MAX_PERCENT_SPREAD = 0.5; private static final long RANDOM_SEED = 177L; + @J2ktIncompatible public void testCombineOrdered_empty() { assertThrows( IllegalArgumentException.class, () -> Hashing.combineOrdered(Collections.emptySet())); } + @J2ktIncompatible public void testCombineOrdered_differentBitLengths() { assertThrows( IllegalArgumentException.class, @@ -277,6 +303,7 @@ public void testCombineOrdered_differentBitLengths() { }); } + @J2ktIncompatible public void testCombineOrdered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); @@ -292,6 +319,7 @@ public void testCombineOrdered() { .equals(Hashing.combineOrdered(ImmutableList.of(hash32, hash31)))); } + @J2ktIncompatible public void testCombineOrdered_randomHashCodes() { Random random = new Random(7); List hashCodes = new ArrayList<>(); @@ -305,12 +333,14 @@ public void testCombineOrdered_randomHashCodes() { assertFalse(hashCode1.equals(hashCode2)); } + @J2ktIncompatible public void testCombineUnordered_empty() { assertThrows( IllegalArgumentException.class, () -> Hashing.combineUnordered(Collections.emptySet())); } + @J2ktIncompatible public void testCombineUnordered_differentBitLengths() { assertThrows( IllegalArgumentException.class, @@ -321,6 +351,7 @@ public void testCombineUnordered_differentBitLengths() { }); } + @J2ktIncompatible public void testCombineUnordered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); @@ -333,6 +364,7 @@ public void testCombineUnordered() { Hashing.combineUnordered(ImmutableList.of(hash32, hash31))); } + @J2ktIncompatible public void testCombineUnordered_randomHashCodes() { Random random = new Random(RANDOM_SEED); List hashCodes = new ArrayList<>(); @@ -347,6 +379,7 @@ public void testCombineUnordered_randomHashCodes() { } // This isn't specified by contract, but it'll still be nice to know if this behavior changes. + @J2ktIncompatible public void testConcatenating_equals() { new EqualsTester() .addEqualityGroup(Hashing.concatenating(asList(Hashing.md5()))) @@ -363,6 +396,7 @@ public void testConcatenating_equals() { .testEquals(); } + @J2ktIncompatible public void testConcatenatingIterable_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), @@ -376,6 +410,7 @@ public void testConcatenatingIterable_bits() { .bits()); } + @J2ktIncompatible public void testConcatenatingVarArgs_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), @@ -388,6 +423,7 @@ public void testConcatenatingVarArgs_bits() { Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32(), Hashing.murmur3_128()).bits()); } + @J2ktIncompatible public void testConcatenatingHashFunction_makeHash() { byte[] md5Hash = Hashing.md5().hashLong(42L).asBytes(); byte[] murmur3Hash = Hashing.murmur3_32().hashLong(42L).asBytes(); @@ -403,6 +439,7 @@ public void testConcatenatingHashFunction_makeHash() { expected, Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())).hashLong(42L)); } + @J2ktIncompatible public void testHashIntReverseBytesVsHashBytesIntsToByteArray() { int input = 42; assertEquals( @@ -410,6 +447,7 @@ public void testHashIntReverseBytesVsHashBytesIntsToByteArray() { Hashing.md5().hashInt(Integer.reverseBytes(input))); } + @J2ktIncompatible public void testHashIntVsForLoop() { int input = 42; HashCode expected = Hashing.md5().hashInt(input); @@ -426,6 +464,8 @@ public void testHashIntVsForLoop() { private static final String TQBFJOTLD = "The quick brown fox jumps over the lazy dog"; private static final String TQBFJOTLDP = "The quick brown fox jumps over the lazy dog."; + // TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these. + // (And un-@J2ktIncompatible any tests above for algorithms that it does support!) private static final ImmutableTable KNOWN_HASHES = ImmutableTable.builder() .put(Hashing.adler32(), "", "01000000") @@ -505,6 +545,7 @@ public void testHashIntVsForLoop() { .put(Hashing.fingerprint2011(), TQBFJOTLDP, "a714d70f1d569cd0") .build(); + @J2ktIncompatible public void testAllHashFunctionsHaveKnownHashes() throws Exception { for (Method method : Hashing.class.getDeclaredMethods()) { if (shouldHaveKnownHashes(method)) { @@ -527,6 +568,7 @@ public void testKnownUtf8Hashing() { } } + @J2ktIncompatible public void testNullPointers() { NullPointerTester tester = new NullPointerTester() @@ -535,10 +577,12 @@ public void testNullPointers() { tester.testAllPublicStaticMethods(Hashing.class); } + @J2ktIncompatible public void testSeedlessHashFunctionEquals() throws Exception { assertSeedlessHashFunctionEquals(Hashing.class); } + @J2ktIncompatible public void testSeededHashFunctionEquals() throws Exception { assertSeededHashFunctionEquals(Hashing.class); } @@ -550,6 +594,7 @@ public void testSeededHashFunctionEquals() throws Exception { * different parameters can be equal. That fact is a problem for {@code * testSeededHashFunctionEquals}. */ + @J2ktIncompatible public void testGoodFastHashEquals() throws Exception { HashFunction hashFunction1a = Hashing.goodFastHash(1); HashFunction hashFunction1b = Hashing.goodFastHash(32); @@ -573,6 +618,7 @@ public void testGoodFastHashEquals() throws Exception { assertThat(hashFunction4b.toString()).isEqualTo(hashFunction4a.toString()); } + @J2ktIncompatible static void assertSeedlessHashFunctionEquals(Class clazz) throws Exception { for (Method method : clazz.getDeclaredMethods()) { if (shouldHaveKnownHashes(method)) { @@ -589,6 +635,7 @@ static void assertSeedlessHashFunctionEquals(Class clazz) throws Exception { } } + @J2ktIncompatible private static boolean shouldHaveKnownHashes(Method method) { // The following legacy hashing function methods have been covered by unit testing already. ImmutableSet legacyHashingMethodNames = @@ -599,6 +646,7 @@ private static boolean shouldHaveKnownHashes(Method method) { && !legacyHashingMethodNames.contains(method.getName()); } + @J2ktIncompatible static void assertSeededHashFunctionEquals(Class clazz) throws Exception { Random random = new Random(RANDOM_SEED); for (Method method : clazz.getDeclaredMethods()) { diff --git a/android/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java index 6b9cfa185ecd..6f94ccfd1e7b 100644 --- a/android/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java @@ -25,6 +25,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Table; @@ -46,6 +47,7 @@ * @author Kurt Alfred Kluever */ @NullUnmarked +@J2ktIncompatible public class MacHashFunctionTest extends TestCase { private static final ImmutableSet INPUTS = ImmutableSet.of("", "Z", "foobar"); diff --git a/android/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java index c0f33e5deb0c..afb1bb65b33b 100644 --- a/android/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java @@ -48,6 +48,7 @@ public class MessageDigestHashFunctionTest extends TestCase { // - For example, the "SHA-1" algorithm might be referred to as "SHA1". // - The algorithm name is not case-sensitive. @SuppressWarnings("deprecation") // We still need to test our deprecated APIs. + // TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these. private static final ImmutableMap ALGORITHMS = new ImmutableMap.Builder() .put("MD5", md5()) diff --git a/android/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java b/android/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java index 0148cb08483a..9e957a014197 100644 --- a/android/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java +++ b/android/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.hash.HashTestUtils.HashFn; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -29,6 +30,7 @@ /** Tests for {@link Murmur3_128HashFunction}. */ @NullUnmarked +@J2ktIncompatible public class Murmur3Hash128Test extends TestCase { public void testKnownValues() { assertHash(0, 0x629942693e10f867L, 0x92db0b82baeb5347L, "hell"); diff --git a/android/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java b/android/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java index 975375fbadbd..863c93328c71 100644 --- a/android/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java +++ b/android/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java @@ -23,6 +23,7 @@ import static java.nio.charset.StandardCharsets.UTF_16LE; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.hash.HashTestUtils.HashFn; import java.nio.charset.Charset; import java.util.Random; @@ -31,6 +32,7 @@ /** Tests for {@link Murmur3_32HashFunction}. */ @NullUnmarked +@J2ktIncompatible public class Murmur3Hash32Test extends TestCase { public void testKnownIntegerInputs() { assertHash(593689054, murmur3_32().hashInt(0)); diff --git a/android/guava-tests/test/com/google/common/hash/PackageSanityTests.java b/android/guava-tests/test/com/google/common/hash/PackageSanityTests.java index e81d60515839..ea4a2c1cb14b 100644 --- a/android/guava-tests/test/com/google/common/hash/PackageSanityTests.java +++ b/android/guava-tests/test/com/google/common/hash/PackageSanityTests.java @@ -16,6 +16,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray; import com.google.common.testing.AbstractPackageSanityTests; import org.jspecify.annotations.NullUnmarked; @@ -27,6 +28,7 @@ */ @NullUnmarked +@J2ktIncompatible public class PackageSanityTests extends AbstractPackageSanityTests { public PackageSanityTests() { setDefault(LockFreeBitArray.class, new LockFreeBitArray(1)); diff --git a/android/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java b/android/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java index 4faf698f4ff3..1d8ccd913607 100644 --- a/android/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java +++ b/android/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableSet; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -28,6 +29,7 @@ * @author Kurt Alfred Kluever */ @NullUnmarked +@J2ktIncompatible public class SipHashFunctionTest extends TestCase { // From https://131002.net/siphash/siphash24.c diff --git a/android/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java b/android/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java index 15ce417441df..6fa40498422f 100644 --- a/android/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java +++ b/android/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -29,6 +30,7 @@ * * @author Dimitris Andreou */ +@J2ktIncompatible @Immutable abstract class AbstractCompositeHashFunction extends AbstractHashFunction { diff --git a/android/guava/src/com/google/common/hash/AbstractStreamingHasher.java b/android/guava/src/com/google/common/hash/AbstractStreamingHasher.java index e28520d12701..d0374ab9402e 100644 --- a/android/guava/src/com/google/common/hash/AbstractStreamingHasher.java +++ b/android/guava/src/com/google/common/hash/AbstractStreamingHasher.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -28,6 +29,7 @@ * @author Dimitris Andreou */ // TODO(kevinb): this class still needs some design-and-document-for-inheritance love +@J2ktIncompatible abstract class AbstractStreamingHasher extends AbstractHasher { /** Buffer via which we pass data to the hash algorithm (the implementor) */ private final ByteBuffer buffer; diff --git a/android/guava/src/com/google/common/hash/BloomFilter.java b/android/guava/src/com/google/common/hash/BloomFilter.java index adafecc28b68..2263ececce65 100644 --- a/android/guava/src/com/google/common/hash/BloomFilter.java +++ b/android/guava/src/com/google/common/hash/BloomFilter.java @@ -21,6 +21,7 @@ import static java.lang.Math.max; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray; @@ -69,6 +70,7 @@ * @author Kevin Bourrillion * @since 11.0 (thread-safe since 23.0) */ +@J2ktIncompatible @Beta public final class BloomFilter implements Predicate, Serializable { /** diff --git a/android/guava/src/com/google/common/hash/BloomFilterStrategies.java b/android/guava/src/com/google/common/hash/BloomFilterStrategies.java index 66d12d814024..72e19a725ae4 100644 --- a/android/guava/src/com/google/common/hash/BloomFilterStrategies.java +++ b/android/guava/src/com/google/common/hash/BloomFilterStrategies.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.hash.Hashing.murmur3_128; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.math.LongMath; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; @@ -37,6 +38,7 @@ * @author Dimitris Andreou * @author Kurt Alfred Kluever */ +@J2ktIncompatible enum BloomFilterStrategies implements BloomFilter.Strategy { /** * See "Less Hashing, Same Performance: Building a Better Bloom Filter" by Adam Kirsch and Michael diff --git a/android/guava/src/com/google/common/hash/ChecksumHashFunction.java b/android/guava/src/com/google/common/hash/ChecksumHashFunction.java index 380c3a39ab6e..e4a66e02c0c6 100644 --- a/android/guava/src/com/google/common/hash/ChecksumHashFunction.java +++ b/android/guava/src/com/google/common/hash/ChecksumHashFunction.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.io.Serializable; import java.util.zip.Checksum; @@ -26,6 +27,7 @@ * * @author Colin Decker */ +@J2ktIncompatible @Immutable final class ChecksumHashFunction extends AbstractHashFunction implements Serializable { private final ImmutableSupplier checksumSupplier; diff --git a/android/guava/src/com/google/common/hash/Crc32cHashFunction.java b/android/guava/src/com/google/common/hash/Crc32cHashFunction.java index 679c47852062..1a26b94cc018 100644 --- a/android/guava/src/com/google/common/hash/Crc32cHashFunction.java +++ b/android/guava/src/com/google/common/hash/Crc32cHashFunction.java @@ -14,6 +14,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.nio.ByteBuffer; @@ -23,6 +24,7 @@ * * @author Kurt Alfred Kluever */ +@J2ktIncompatible @Immutable final class Crc32cHashFunction extends AbstractHashFunction { static final HashFunction CRC_32_C = new Crc32cHashFunction(); diff --git a/android/guava/src/com/google/common/hash/Fingerprint2011.java b/android/guava/src/com/google/common/hash/Fingerprint2011.java index 74fac1230e88..66621539162a 100644 --- a/android/guava/src/com/google/common/hash/Fingerprint2011.java +++ b/android/guava/src/com/google/common/hash/Fingerprint2011.java @@ -7,6 +7,7 @@ import static com.google.common.hash.LittleEndianByteArray.load64Safely; import static java.lang.Long.rotateRight; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; /** @@ -28,6 +29,7 @@ * @author kylemaddison@google.com (Kyle Maddison) * @author gpike@google.com (Geoff Pike) */ +@J2ktIncompatible final class Fingerprint2011 extends AbstractNonStreamingHashFunction { static final HashFunction FINGERPRINT_2011 = new Fingerprint2011(); diff --git a/android/guava/src/com/google/common/hash/Funnels.java b/android/guava/src/com/google/common/hash/Funnels.java index 387cd87f54d2..456dc06522b8 100644 --- a/android/guava/src/com/google/common/hash/Funnels.java +++ b/android/guava/src/com/google/common/hash/Funnels.java @@ -15,6 +15,7 @@ package com.google.common.hash; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import java.io.InvalidObjectException; import java.io.ObjectInputStream; @@ -29,6 +30,7 @@ * @author Dimitris Andreou * @since 11.0 */ +@J2ktIncompatible @Beta public final class Funnels { private Funnels() {} diff --git a/android/guava/src/com/google/common/hash/HashingInputStream.java b/android/guava/src/com/google/common/hash/HashingInputStream.java index f49dfd62daa5..5eb7b65b6a60 100644 --- a/android/guava/src/com/google/common/hash/HashingInputStream.java +++ b/android/guava/src/com/google/common/hash/HashingInputStream.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.FilterInputStream; import java.io.IOException; @@ -28,6 +29,7 @@ * @author Qian Huang * @since 16.0 */ +@J2ktIncompatible @Beta public final class HashingInputStream extends FilterInputStream { private final Hasher hasher; diff --git a/android/guava/src/com/google/common/hash/HashingOutputStream.java b/android/guava/src/com/google/common/hash/HashingOutputStream.java index 20f1316a558c..b7aa24a22576 100644 --- a/android/guava/src/com/google/common/hash/HashingOutputStream.java +++ b/android/guava/src/com/google/common/hash/HashingOutputStream.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -27,6 +28,7 @@ * @author Zoe Piepmeier * @since 16.0 */ +@J2ktIncompatible @Beta public final class HashingOutputStream extends FilterOutputStream { private final Hasher hasher; diff --git a/android/guava/src/com/google/common/hash/ImmutableSupplier.java b/android/guava/src/com/google/common/hash/ImmutableSupplier.java index b6a74a77b719..d8915f0517d5 100644 --- a/android/guava/src/com/google/common/hash/ImmutableSupplier.java +++ b/android/guava/src/com/google/common/hash/ImmutableSupplier.java @@ -14,6 +14,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Supplier; import com.google.errorprone.annotations.Immutable; @@ -22,5 +23,6 @@ * Immutable}. */ // TODO(cpovirk): Should we just use ChecksumType directly instead of defining this type? +@J2ktIncompatible @Immutable interface ImmutableSupplier extends Supplier {} diff --git a/android/guava/src/com/google/common/hash/MacHashFunction.java b/android/guava/src/com/google/common/hash/MacHashFunction.java index 390b49c30234..b5b7196e3370 100644 --- a/android/guava/src/com/google/common/hash/MacHashFunction.java +++ b/android/guava/src/com/google/common/hash/MacHashFunction.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.nio.ByteBuffer; import java.security.InvalidKeyException; @@ -29,6 +30,7 @@ * * @author Kurt Alfred Kluever */ +@J2ktIncompatible @Immutable final class MacHashFunction extends AbstractHashFunction { diff --git a/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java b/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java index eadce8c1d244..1469d45e77e8 100644 --- a/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java +++ b/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java @@ -28,6 +28,7 @@ import static com.google.common.hash.Hashing.GOOD_FAST_HASH_SEED; import static java.lang.Byte.toUnsignedInt; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.io.Serializable; import java.nio.ByteBuffer; @@ -41,6 +42,7 @@ * @author Austin Appleby * @author Dimitris Andreou */ +@J2ktIncompatible @Immutable @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_128HashFunction extends AbstractHashFunction implements Serializable { diff --git a/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java b/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java index a2b206b127cb..bf092be106e8 100644 --- a/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java +++ b/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java @@ -31,6 +31,7 @@ import static java.lang.Byte.toUnsignedInt; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.primitives.Chars; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; @@ -51,6 +52,7 @@ * @author Dimitris Andreou * @author Kurt Alfred Kluever */ +@J2ktIncompatible @Immutable @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_32HashFunction extends AbstractHashFunction implements Serializable { diff --git a/android/guava/src/com/google/common/hash/SipHashFunction.java b/android/guava/src/com/google/common/hash/SipHashFunction.java index a5f328c3f3fc..fc0ef8baaa55 100644 --- a/android/guava/src/com/google/common/hash/SipHashFunction.java +++ b/android/guava/src/com/google/common/hash/SipHashFunction.java @@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.io.Serializable; import java.nio.ByteBuffer; @@ -33,6 +34,7 @@ * @author Jean-Philippe Aumasson * @author Daniel J. Bernstein */ +@J2ktIncompatible @Immutable final class SipHashFunction extends AbstractHashFunction implements Serializable { static final HashFunction SIP_HASH_24 = diff --git a/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java index 5e01f61977fd..cc387b0cc593 100644 --- a/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractByteHasherTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import java.io.ByteArrayOutputStream; import java.util.Random; import junit.framework.TestCase; @@ -66,6 +67,7 @@ public void testChar() { hasher.assertBytes(new byte[] {1, 2}); } + @J2ktIncompatible // no UTF_16LE support public void testString() { Random random = new Random(); for (int i = 0; i < 100; i++) { diff --git a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java index 281ec4fef5a4..047e90eaa6f3 100644 --- a/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractNonStreamingHashFunctionTest.java @@ -16,6 +16,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.common.hash.HashTestUtils.RandomHasherAction; import java.io.ByteArrayOutputStream; @@ -34,6 +35,7 @@ public class AbstractNonStreamingHashFunctionTest extends TestCase { * and checks that their results are identical, no matter which newHasher version we used. */ public void testExhaustive() { + // TODO: b/484953702 - Split test so we can avoid StreamingVersion under J2KT. List hashers = ImmutableList.of( new StreamingVersion().newHasher(), @@ -93,6 +95,7 @@ private static void assertPutString(char[] chars) { assertEquals(h1.hash(), h2.hash()); } + @J2ktIncompatible // AbstractStreamingHasher static class StreamingVersion extends AbstractHashFunction { @Override public int bits() { diff --git a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java index 13b96eef159f..1d6a1bd7c3ca 100644 --- a/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java +++ b/guava-tests/test/com/google/common/hash/AbstractStreamingHasherTest.java @@ -21,6 +21,7 @@ import static java.util.Collections.singleton; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.Iterables; import com.google.common.hash.HashTestUtils.RandomHasherAction; import java.io.ByteArrayOutputStream; @@ -38,6 +39,9 @@ * * @author Dimitris Andreou */ +// All tests use Sink, which uses the currently J2KT-incompatible AbstractStreamingHasher +// (Plus, testString in particular requires UTF_16LE support.) +@J2ktIncompatible @NullUnmarked public class AbstractStreamingHasherTest extends TestCase { public void testBytes() { diff --git a/guava-tests/test/com/google/common/hash/BloomFilterTest.java b/guava-tests/test/com/google/common/hash/BloomFilterTest.java index 82e0e90023a0..a1fdf2ea59de 100644 --- a/guava-tests/test/com/google/common/hash/BloomFilterTest.java +++ b/guava-tests/test/com/google/common/hash/BloomFilterTest.java @@ -29,6 +29,7 @@ import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableSet; import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray; @@ -54,6 +55,7 @@ * @author Dimitris Andreou */ @NullUnmarked +@J2ktIncompatible public class BloomFilterTest extends TestCase { private static final int NUM_PUTS = 100_000; private static final ThreadLocal random = diff --git a/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java b/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java index 5fcc3a0e4c57..91cd0d7497fe 100644 --- a/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java @@ -18,6 +18,7 @@ import static com.google.common.hash.Hashing.ChecksumType.CRC_32; import static com.google.common.truth.Truth.assertThat; +import com.google.common.annotations.J2ktIncompatible; import java.util.zip.Checksum; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -28,6 +29,7 @@ * @author Colin Decker */ @NullUnmarked +@J2ktIncompatible public class ChecksumHashFunctionTest extends TestCase { public void testCrc32_equalsChecksumValue() throws Exception { diff --git a/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java b/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java index 85c5cf84fbfc..2554f09a720d 100644 --- a/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/Crc32cHashFunctionTest.java @@ -17,6 +17,7 @@ import static com.google.common.hash.Hashing.crc32c; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import java.util.Arrays; import java.util.Random; import junit.framework.TestCase; @@ -29,6 +30,7 @@ * @author Kurt Alfred Kluever */ @NullUnmarked +@J2ktIncompatible public class Crc32cHashFunctionTest extends TestCase { public void testEmpty() { assertCrc(0, new byte[0]); diff --git a/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java b/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java index c857c55acd3a..a6057e13f539 100644 --- a/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java +++ b/guava-tests/test/com/google/common/hash/Fingerprint2011Test.java @@ -8,6 +8,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.asList; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Ordering; @@ -21,6 +22,7 @@ * @author kylemaddison@google.com (Kyle Maddison) */ @NullUnmarked +@J2ktIncompatible public class Fingerprint2011Test extends TestCase { // Length of the sample string to produce diff --git a/guava-tests/test/com/google/common/hash/FunnelsTest.java b/guava-tests/test/com/google/common/hash/FunnelsTest.java index a065af02580c..6ec6ab1e00c2 100644 --- a/guava-tests/test/com/google/common/hash/FunnelsTest.java +++ b/guava-tests/test/com/google/common/hash/FunnelsTest.java @@ -32,6 +32,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.testing.EqualsTester; import java.io.OutputStream; import java.nio.ByteBuffer; @@ -45,6 +46,7 @@ * * @author Dimitris Andreou */ +@J2ktIncompatible @NullUnmarked public class FunnelsTest extends TestCase { public void testForBytes() { diff --git a/guava-tests/test/com/google/common/hash/HashCodeTest.java b/guava-tests/test/com/google/common/hash/HashCodeTest.java index 35c8865c2150..3da0cb7ef5e3 100644 --- a/guava-tests/test/com/google/common/hash/HashCodeTest.java +++ b/guava-tests/test/com/google/common/hash/HashCodeTest.java @@ -16,12 +16,13 @@ package com.google.common.hash; -import static com.google.common.hash.Hashing.sha1; +import static com.google.common.hash.Hashing.farmHashFingerprint64; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.US_ASCII; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.common.io.BaseEncoding; import com.google.common.testing.ClassSanityTester; @@ -178,16 +179,18 @@ public void testToString() { assertThat(base16().lowerCase().encode(data)).isEqualTo("7f8005ff0e"); } + @J2ktIncompatible // ClassSanityTester public void testHashCode_nulls() throws Exception { sanityTester().testNulls(); } + @J2ktIncompatible // ClassSanityTester public void testHashCode_equalsAndSerializable() throws Exception { sanityTester().testEqualsAndSerializable(); } public void testRoundTripHashCodeUsingBaseEncoding() { - HashCode hash1 = sha1().hashString("foo", US_ASCII); + HashCode hash1 = farmHashFingerprint64().hashString("foo", US_ASCII); HashCode hash2 = HashCode.fromBytes(BaseEncoding.base16().lowerCase().decode(hash1.toString())); assertEquals(hash1, hash2); } @@ -219,7 +222,7 @@ public void testObjectHashCodeWithSameLowOrderBytes() { } public void testRoundTripHashCodeUsingFromString() { - HashCode hash1 = sha1().hashString("foo", US_ASCII); + HashCode hash1 = farmHashFingerprint64().hashString("foo", US_ASCII); HashCode hash2 = HashCode.fromString(hash1.toString()); assertEquals(hash1, hash2); } @@ -238,7 +241,7 @@ public void testFromStringFailsWithInvalidHexChar() { } public void testFromStringFailsWithUpperCaseString() { - String string = sha1().hashString("foo", US_ASCII).toString().toUpperCase(); + String string = farmHashFingerprint64().hashString("foo", US_ASCII).toString().toUpperCase(); assertThrows(IllegalArgumentException.class, () -> HashCode.fromString(string)); } @@ -310,6 +313,7 @@ public void testWriteBytesToUndersizedArrayShortMaxLength() { assertThat(dest).isEqualTo(new byte[] {(byte) 0xaa, (byte) 0xbb, (byte) 0x00}); } + @J2ktIncompatible // ClassSanityTester private static ClassSanityTester.FactoryMethodReturnValueTester sanityTester() { return new ClassSanityTester() .setDefault(byte[].class, new byte[] {1, 2, 3, 4}) @@ -357,7 +361,7 @@ private static void assertReadableBytes(HashCode hashCode) { private static class ExpectedHashCode { final byte[] bytes; final int asInt; - final Long asLong; // null means that asLong should throw an exception + final @Nullable Long asLong; // null means that asLong should throw an exception final String toString; ExpectedHashCode(byte[] bytes, int asInt, @Nullable Long asLong, String toString) { diff --git a/guava-tests/test/com/google/common/hash/HashFunctionEnum.java b/guava-tests/test/com/google/common/hash/HashFunctionEnum.java index 2258e84d86b6..7f1097d8a550 100644 --- a/guava-tests/test/com/google/common/hash/HashFunctionEnum.java +++ b/guava-tests/test/com/google/common/hash/HashFunctionEnum.java @@ -30,6 +30,7 @@ import static com.google.common.hash.Hashing.sha512; import static com.google.common.hash.Hashing.sipHash24; +import com.google.common.annotations.J2ktIncompatible; import org.jspecify.annotations.NullUnmarked; /** @@ -39,6 +40,7 @@ */ @SuppressWarnings("deprecation") // We still need to test our deprecated APIs. @NullUnmarked +@J2ktIncompatible enum HashFunctionEnum { ADLER32(adler32()), CRC32(crc32()), diff --git a/guava-tests/test/com/google/common/hash/HashTestUtils.java b/guava-tests/test/com/google/common/hash/HashTestUtils.java index 3fda291072d4..65be7c52415d 100644 --- a/guava-tests/test/com/google/common/hash/HashTestUtils.java +++ b/guava-tests/test/com/google/common/hash/HashTestUtils.java @@ -636,6 +636,7 @@ private static void assertHashLongEquivalence(HashFunction hashFunction, Random assertEquals(hashFunction.hashLong(l), hashFunction.newHasher().putLong(l).hash()); } + // TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these. private static final ImmutableSet CHARSETS = ImmutableSet.of(ISO_8859_1, US_ASCII, UTF_16, UTF_16BE, UTF_16LE, UTF_8); diff --git a/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java b/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java index d88d4b495d90..f4777fab0828 100644 --- a/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java +++ b/guava-tests/test/com/google/common/hash/HashingInputStreamTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.testing.NullPointerTester; import java.io.ByteArrayInputStream; import java.util.Arrays; @@ -33,6 +34,7 @@ * @author Qian Huang */ @NullUnmarked +@J2ktIncompatible public class HashingInputStreamTest extends TestCase { private Hasher hasher; private HashFunction hashFunction; diff --git a/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java b/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java index c6e096d74c4b..73929af03b33 100644 --- a/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java +++ b/guava-tests/test/com/google/common/hash/HashingOutputStreamTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.testing.NullPointerTester; import java.io.ByteArrayOutputStream; import junit.framework.TestCase; @@ -31,6 +32,7 @@ * @author Zoe Piepmeier */ @NullUnmarked +@J2ktIncompatible public class HashingOutputStreamTest extends TestCase { private Hasher hasher; private HashFunction hashFunction; diff --git a/guava-tests/test/com/google/common/hash/HashingTest.java b/guava-tests/test/com/google/common/hash/HashingTest.java index 573ed7e4a8c3..60abf1d58363 100644 --- a/guava-tests/test/com/google/common/hash/HashingTest.java +++ b/guava-tests/test/com/google/common/hash/HashingTest.java @@ -23,6 +23,7 @@ import static java.util.Collections.shuffle; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableTable; @@ -53,6 +54,7 @@ */ @NullUnmarked public class HashingTest extends TestCase { + @J2ktIncompatible public void testMd5() { HashTestUtils.checkAvalanche(Hashing.md5(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.md5()); @@ -61,6 +63,7 @@ public void testMd5() { assertThat(Hashing.md5().toString()).isEqualTo("Hashing.md5()"); } + @J2ktIncompatible public void testSha1() { HashTestUtils.checkAvalanche(Hashing.sha1(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha1()); @@ -69,6 +72,7 @@ public void testSha1() { assertThat(Hashing.sha1().toString()).isEqualTo("Hashing.sha1()"); } + @J2ktIncompatible public void testSha256() { HashTestUtils.checkAvalanche(Hashing.sha256(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha256()); @@ -77,6 +81,7 @@ public void testSha256() { assertThat(Hashing.sha256().toString()).isEqualTo("Hashing.sha256()"); } + @J2ktIncompatible public void testSha384() { HashTestUtils.checkAvalanche(Hashing.sha384(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha384()); @@ -85,6 +90,7 @@ public void testSha384() { assertThat(Hashing.sha384().toString()).isEqualTo("Hashing.sha384()"); } + @J2ktIncompatible public void testSha512() { HashTestUtils.checkAvalanche(Hashing.sha512(), 100, 0.4); HashTestUtils.checkNo2BitCharacteristics(Hashing.sha512()); @@ -93,16 +99,19 @@ public void testSha512() { assertThat(Hashing.sha512().toString()).isEqualTo("Hashing.sha512()"); } + @J2ktIncompatible public void testCrc32() { HashTestUtils.assertInvariants(Hashing.crc32()); assertThat(Hashing.crc32().toString()).isEqualTo("Hashing.crc32()"); } + @J2ktIncompatible public void testAdler32() { HashTestUtils.assertInvariants(Hashing.adler32()); assertThat(Hashing.adler32().toString()).isEqualTo("Hashing.adler32()"); } + @J2ktIncompatible public void testMurmur3_128() { HashTestUtils.check2BitAvalanche(Hashing.murmur3_128(), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.murmur3_128(), 250, 0.17); @@ -112,6 +121,7 @@ public void testMurmur3_128() { assertThat(Hashing.murmur3_128().toString()).isEqualTo("Hashing.murmur3_128(0)"); } + @J2ktIncompatible public void testMurmur3_32() { HashTestUtils.check2BitAvalanche(Hashing.murmur3_32(), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.murmur3_32(), 250, 0.17); @@ -121,6 +131,7 @@ public void testMurmur3_32() { assertThat(Hashing.murmur3_32().toString()).isEqualTo("Hashing.murmur3_32(0)"); } + @J2ktIncompatible public void testSipHash24() { HashTestUtils.check2BitAvalanche(Hashing.sipHash24(), 250, 0.14); HashTestUtils.checkAvalanche(Hashing.sipHash24(), 250, 0.10); @@ -131,6 +142,7 @@ public void testSipHash24() { .isEqualTo("Hashing.sipHash24(506097522914230528, 1084818905618843912)"); } + @J2ktIncompatible public void testFingerprint2011() { HashTestUtils.check2BitAvalanche(Hashing.fingerprint2011(), 100, 0.4); HashTestUtils.checkAvalanche(Hashing.fingerprint2011(), 100, 0.4); @@ -141,6 +153,7 @@ public void testFingerprint2011() { } @AndroidIncompatible // slow TODO(cpovirk): Maybe just reduce iterations under Android. + @J2ktIncompatible public void testGoodFastHash() { for (int i = 1; i < 200; i += 17) { HashFunction hasher = Hashing.goodFastHash(i); @@ -150,6 +163,7 @@ public void testGoodFastHash() { } // goodFastHash(32) uses Murmur3_32. Use the same epsilon bounds. + @J2ktIncompatible public void testGoodFastHash32() { HashTestUtils.check2BitAvalanche(Hashing.goodFastHash(32), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.goodFastHash(32), 250, 0.17); @@ -159,6 +173,7 @@ public void testGoodFastHash32() { } // goodFastHash(128) uses Murmur3_128. Use the same epsilon bounds. + @J2ktIncompatible public void testGoodFastHash128() { HashTestUtils.check2BitAvalanche(Hashing.goodFastHash(128), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.goodFastHash(128), 500, 0.17); @@ -168,6 +183,7 @@ public void testGoodFastHash128() { } // goodFastHash(256) uses Murmur3_128. Use the same epsilon bounds. + @J2ktIncompatible public void testGoodFastHash256() { HashTestUtils.check2BitAvalanche(Hashing.goodFastHash(256), 250, 0.20); HashTestUtils.checkAvalanche(Hashing.goodFastHash(256), 500, 0.17); @@ -176,6 +192,7 @@ public void testGoodFastHash256() { HashTestUtils.assertInvariants(Hashing.goodFastHash(256)); } + @J2ktIncompatible public void testConsistentHash_correctness() { long[] interestingValues = {-1, 0, 1, 2, Long.MAX_VALUE, Long.MIN_VALUE}; for (long h : interestingValues) { @@ -187,6 +204,7 @@ public void testConsistentHash_correctness() { } } + @J2ktIncompatible private void checkConsistentHashCorrectness(long hashCode) { int last = 0; for (int shards = 1; shards <= 100000; shards++) { @@ -198,6 +216,7 @@ private void checkConsistentHashCorrectness(long hashCode) { } } + @J2ktIncompatible public void testConsistentHash_probabilities() { AtomicLongMap map = AtomicLongMap.create(); Random r = new Random(9); @@ -210,6 +229,7 @@ public void testConsistentHash_probabilities() { } } + @J2ktIncompatible private void countRemaps(long h, AtomicLongMap map) { int last = 0; for (int shards = 2; shards <= MAX_SHARDS; shards++) { @@ -224,16 +244,19 @@ private void countRemaps(long h, AtomicLongMap map) { private static final int ITERS = 10000; private static final int MAX_SHARDS = 500; + @J2ktIncompatible public void testConsistentHash_outOfRange() { assertThrows(IllegalArgumentException.class, () -> Hashing.consistentHash(5L, 0)); } + @J2ktIncompatible public void testConsistentHash_ofHashCode() { checkSameResult(HashCode.fromLong(1), 1); checkSameResult(HashCode.fromLong(0x9999999999999999L), 0x9999999999999999L); checkSameResult(HashCode.fromInt(0x99999999), 0x0000000099999999L); } + @J2ktIncompatible public void checkSameResult(HashCode hashCode, long equivLong) { assertEquals(Hashing.consistentHash(equivLong, 5555), Hashing.consistentHash(hashCode, 5555)); } @@ -242,6 +265,7 @@ public void checkSameResult(HashCode hashCode, long equivLong) { * Check a few "golden" values to see that implementations across languages are equivalent. * */ + @J2ktIncompatible public void testConsistentHash_linearCongruentialGeneratorCompatibility() { int[] golden100 = { 0, 55, 62, 8, 45, 59, 86, 97, 82, 59, @@ -261,12 +285,14 @@ public void testConsistentHash_linearCongruentialGeneratorCompatibility() { private static final double MAX_PERCENT_SPREAD = 0.5; private static final long RANDOM_SEED = 177L; + @J2ktIncompatible public void testCombineOrdered_empty() { assertThrows( IllegalArgumentException.class, () -> Hashing.combineOrdered(Collections.emptySet())); } + @J2ktIncompatible public void testCombineOrdered_differentBitLengths() { assertThrows( IllegalArgumentException.class, @@ -277,6 +303,7 @@ public void testCombineOrdered_differentBitLengths() { }); } + @J2ktIncompatible public void testCombineOrdered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); @@ -292,6 +319,7 @@ public void testCombineOrdered() { .equals(Hashing.combineOrdered(ImmutableList.of(hash32, hash31)))); } + @J2ktIncompatible public void testCombineOrdered_randomHashCodes() { Random random = new Random(7); List hashCodes = new ArrayList<>(); @@ -305,12 +333,14 @@ public void testCombineOrdered_randomHashCodes() { assertFalse(hashCode1.equals(hashCode2)); } + @J2ktIncompatible public void testCombineUnordered_empty() { assertThrows( IllegalArgumentException.class, () -> Hashing.combineUnordered(Collections.emptySet())); } + @J2ktIncompatible public void testCombineUnordered_differentBitLengths() { assertThrows( IllegalArgumentException.class, @@ -321,6 +351,7 @@ public void testCombineUnordered_differentBitLengths() { }); } + @J2ktIncompatible public void testCombineUnordered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); @@ -333,6 +364,7 @@ public void testCombineUnordered() { Hashing.combineUnordered(ImmutableList.of(hash32, hash31))); } + @J2ktIncompatible public void testCombineUnordered_randomHashCodes() { Random random = new Random(RANDOM_SEED); List hashCodes = new ArrayList<>(); @@ -347,6 +379,7 @@ public void testCombineUnordered_randomHashCodes() { } // This isn't specified by contract, but it'll still be nice to know if this behavior changes. + @J2ktIncompatible public void testConcatenating_equals() { new EqualsTester() .addEqualityGroup(Hashing.concatenating(asList(Hashing.md5()))) @@ -363,6 +396,7 @@ public void testConcatenating_equals() { .testEquals(); } + @J2ktIncompatible public void testConcatenatingIterable_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), @@ -376,6 +410,7 @@ public void testConcatenatingIterable_bits() { .bits()); } + @J2ktIncompatible public void testConcatenatingVarArgs_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), @@ -388,6 +423,7 @@ public void testConcatenatingVarArgs_bits() { Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32(), Hashing.murmur3_128()).bits()); } + @J2ktIncompatible public void testConcatenatingHashFunction_makeHash() { byte[] md5Hash = Hashing.md5().hashLong(42L).asBytes(); byte[] murmur3Hash = Hashing.murmur3_32().hashLong(42L).asBytes(); @@ -403,6 +439,7 @@ public void testConcatenatingHashFunction_makeHash() { expected, Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())).hashLong(42L)); } + @J2ktIncompatible public void testHashIntReverseBytesVsHashBytesIntsToByteArray() { int input = 42; assertEquals( @@ -410,6 +447,7 @@ public void testHashIntReverseBytesVsHashBytesIntsToByteArray() { Hashing.md5().hashInt(Integer.reverseBytes(input))); } + @J2ktIncompatible public void testHashIntVsForLoop() { int input = 42; HashCode expected = Hashing.md5().hashInt(input); @@ -426,6 +464,8 @@ public void testHashIntVsForLoop() { private static final String TQBFJOTLD = "The quick brown fox jumps over the lazy dog"; private static final String TQBFJOTLDP = "The quick brown fox jumps over the lazy dog."; + // TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these. + // (And un-@J2ktIncompatible any tests above for algorithms that it does support!) private static final ImmutableTable KNOWN_HASHES = ImmutableTable.builder() .put(Hashing.adler32(), "", "01000000") @@ -505,6 +545,7 @@ public void testHashIntVsForLoop() { .put(Hashing.fingerprint2011(), TQBFJOTLDP, "a714d70f1d569cd0") .build(); + @J2ktIncompatible public void testAllHashFunctionsHaveKnownHashes() throws Exception { for (Method method : Hashing.class.getDeclaredMethods()) { if (shouldHaveKnownHashes(method)) { @@ -527,6 +568,7 @@ public void testKnownUtf8Hashing() { } } + @J2ktIncompatible public void testNullPointers() { NullPointerTester tester = new NullPointerTester() @@ -535,10 +577,12 @@ public void testNullPointers() { tester.testAllPublicStaticMethods(Hashing.class); } + @J2ktIncompatible public void testSeedlessHashFunctionEquals() throws Exception { assertSeedlessHashFunctionEquals(Hashing.class); } + @J2ktIncompatible public void testSeededHashFunctionEquals() throws Exception { assertSeededHashFunctionEquals(Hashing.class); } @@ -550,6 +594,7 @@ public void testSeededHashFunctionEquals() throws Exception { * different parameters can be equal. That fact is a problem for {@code * testSeededHashFunctionEquals}. */ + @J2ktIncompatible public void testGoodFastHashEquals() throws Exception { HashFunction hashFunction1a = Hashing.goodFastHash(1); HashFunction hashFunction1b = Hashing.goodFastHash(32); @@ -573,6 +618,7 @@ public void testGoodFastHashEquals() throws Exception { assertThat(hashFunction4b.toString()).isEqualTo(hashFunction4a.toString()); } + @J2ktIncompatible static void assertSeedlessHashFunctionEquals(Class clazz) throws Exception { for (Method method : clazz.getDeclaredMethods()) { if (shouldHaveKnownHashes(method)) { @@ -589,6 +635,7 @@ static void assertSeedlessHashFunctionEquals(Class clazz) throws Exception { } } + @J2ktIncompatible private static boolean shouldHaveKnownHashes(Method method) { // The following legacy hashing function methods have been covered by unit testing already. ImmutableSet legacyHashingMethodNames = @@ -599,6 +646,7 @@ private static boolean shouldHaveKnownHashes(Method method) { && !legacyHashingMethodNames.contains(method.getName()); } + @J2ktIncompatible static void assertSeededHashFunctionEquals(Class clazz) throws Exception { Random random = new Random(RANDOM_SEED); for (Method method : clazz.getDeclaredMethods()) { diff --git a/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java b/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java index 6b9cfa185ecd..6f94ccfd1e7b 100644 --- a/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/MacHashFunctionTest.java @@ -25,6 +25,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertThrows; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableTable; import com.google.common.collect.Table; @@ -46,6 +47,7 @@ * @author Kurt Alfred Kluever */ @NullUnmarked +@J2ktIncompatible public class MacHashFunctionTest extends TestCase { private static final ImmutableSet INPUTS = ImmutableSet.of("", "Z", "foobar"); diff --git a/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java b/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java index c0f33e5deb0c..afb1bb65b33b 100644 --- a/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java @@ -48,6 +48,7 @@ public class MessageDigestHashFunctionTest extends TestCase { // - For example, the "SHA-1" algorithm might be referred to as "SHA1". // - The algorithm name is not case-sensitive. @SuppressWarnings("deprecation") // We still need to test our deprecated APIs. + // TODO: b/484953702 - Put a list in TestPlatform so that J2KT can omit some of these. private static final ImmutableMap ALGORITHMS = new ImmutableMap.Builder() .put("MD5", md5()) diff --git a/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java b/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java index 0148cb08483a..9e957a014197 100644 --- a/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java +++ b/guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.hash.HashTestUtils.HashFn; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -29,6 +30,7 @@ /** Tests for {@link Murmur3_128HashFunction}. */ @NullUnmarked +@J2ktIncompatible public class Murmur3Hash128Test extends TestCase { public void testKnownValues() { assertHash(0, 0x629942693e10f867L, 0x92db0b82baeb5347L, "hell"); diff --git a/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java b/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java index 975375fbadbd..863c93328c71 100644 --- a/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java +++ b/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java @@ -23,6 +23,7 @@ import static java.nio.charset.StandardCharsets.UTF_16LE; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.hash.HashTestUtils.HashFn; import java.nio.charset.Charset; import java.util.Random; @@ -31,6 +32,7 @@ /** Tests for {@link Murmur3_32HashFunction}. */ @NullUnmarked +@J2ktIncompatible public class Murmur3Hash32Test extends TestCase { public void testKnownIntegerInputs() { assertHash(593689054, murmur3_32().hashInt(0)); diff --git a/guava-tests/test/com/google/common/hash/PackageSanityTests.java b/guava-tests/test/com/google/common/hash/PackageSanityTests.java index e81d60515839..ea4a2c1cb14b 100644 --- a/guava-tests/test/com/google/common/hash/PackageSanityTests.java +++ b/guava-tests/test/com/google/common/hash/PackageSanityTests.java @@ -16,6 +16,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray; import com.google.common.testing.AbstractPackageSanityTests; import org.jspecify.annotations.NullUnmarked; @@ -27,6 +28,7 @@ */ @NullUnmarked +@J2ktIncompatible public class PackageSanityTests extends AbstractPackageSanityTests { public PackageSanityTests() { setDefault(LockFreeBitArray.class, new LockFreeBitArray(1)); diff --git a/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java b/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java index 4faf698f4ff3..1d8ccd913607 100644 --- a/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java +++ b/guava-tests/test/com/google/common/hash/SipHashFunctionTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.collect.ImmutableSet; import junit.framework.TestCase; import org.jspecify.annotations.NullUnmarked; @@ -28,6 +29,7 @@ * @author Kurt Alfred Kluever */ @NullUnmarked +@J2ktIncompatible public class SipHashFunctionTest extends TestCase { // From https://131002.net/siphash/siphash24.c diff --git a/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java b/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java index 15ce417441df..6fa40498422f 100644 --- a/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java +++ b/guava/src/com/google/common/hash/AbstractCompositeHashFunction.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -29,6 +30,7 @@ * * @author Dimitris Andreou */ +@J2ktIncompatible @Immutable abstract class AbstractCompositeHashFunction extends AbstractHashFunction { diff --git a/guava/src/com/google/common/hash/AbstractStreamingHasher.java b/guava/src/com/google/common/hash/AbstractStreamingHasher.java index e28520d12701..d0374ab9402e 100644 --- a/guava/src/com/google/common/hash/AbstractStreamingHasher.java +++ b/guava/src/com/google/common/hash/AbstractStreamingHasher.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -28,6 +29,7 @@ * @author Dimitris Andreou */ // TODO(kevinb): this class still needs some design-and-document-for-inheritance love +@J2ktIncompatible abstract class AbstractStreamingHasher extends AbstractHasher { /** Buffer via which we pass data to the hash algorithm (the implementor) */ private final ByteBuffer buffer; diff --git a/guava/src/com/google/common/hash/BloomFilter.java b/guava/src/com/google/common/hash/BloomFilter.java index 9a0093934123..0a3209d46d50 100644 --- a/guava/src/com/google/common/hash/BloomFilter.java +++ b/guava/src/com/google/common/hash/BloomFilter.java @@ -21,6 +21,7 @@ import static java.lang.Math.max; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Predicate; import com.google.common.hash.BloomFilterStrategies.LockFreeBitArray; @@ -69,6 +70,7 @@ * @author Kevin Bourrillion * @since 11.0 (thread-safe since 23.0) */ +@J2ktIncompatible @Beta public final class BloomFilter implements Predicate, Serializable { /** diff --git a/guava/src/com/google/common/hash/BloomFilterStrategies.java b/guava/src/com/google/common/hash/BloomFilterStrategies.java index ee47fddd65de..d45c0ee3716f 100644 --- a/guava/src/com/google/common/hash/BloomFilterStrategies.java +++ b/guava/src/com/google/common/hash/BloomFilterStrategies.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.hash.Hashing.murmur3_128; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.math.LongMath; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; @@ -38,6 +39,7 @@ * @author Dimitris Andreou * @author Kurt Alfred Kluever */ +@J2ktIncompatible enum BloomFilterStrategies implements BloomFilter.Strategy { /** * See "Less Hashing, Same Performance: Building a Better Bloom Filter" by Adam Kirsch and Michael diff --git a/guava/src/com/google/common/hash/ChecksumHashFunction.java b/guava/src/com/google/common/hash/ChecksumHashFunction.java index ad613eba2158..b7d69b49ab27 100644 --- a/guava/src/com/google/common/hash/ChecksumHashFunction.java +++ b/guava/src/com/google/common/hash/ChecksumHashFunction.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.hash.SneakyThrows.sneakyThrow; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import com.google.j2objc.annotations.J2ObjCIncompatible; import java.io.Serializable; @@ -33,6 +34,7 @@ * * @author Colin Decker */ +@J2ktIncompatible @Immutable final class ChecksumHashFunction extends AbstractHashFunction implements Serializable { private final ImmutableSupplier checksumSupplier; diff --git a/guava/src/com/google/common/hash/Crc32cHashFunction.java b/guava/src/com/google/common/hash/Crc32cHashFunction.java index 679c47852062..1a26b94cc018 100644 --- a/guava/src/com/google/common/hash/Crc32cHashFunction.java +++ b/guava/src/com/google/common/hash/Crc32cHashFunction.java @@ -14,6 +14,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.nio.ByteBuffer; @@ -23,6 +24,7 @@ * * @author Kurt Alfred Kluever */ +@J2ktIncompatible @Immutable final class Crc32cHashFunction extends AbstractHashFunction { static final HashFunction CRC_32_C = new Crc32cHashFunction(); diff --git a/guava/src/com/google/common/hash/Fingerprint2011.java b/guava/src/com/google/common/hash/Fingerprint2011.java index 74fac1230e88..66621539162a 100644 --- a/guava/src/com/google/common/hash/Fingerprint2011.java +++ b/guava/src/com/google/common/hash/Fingerprint2011.java @@ -7,6 +7,7 @@ import static com.google.common.hash.LittleEndianByteArray.load64Safely; import static java.lang.Long.rotateRight; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; /** @@ -28,6 +29,7 @@ * @author kylemaddison@google.com (Kyle Maddison) * @author gpike@google.com (Geoff Pike) */ +@J2ktIncompatible final class Fingerprint2011 extends AbstractNonStreamingHashFunction { static final HashFunction FINGERPRINT_2011 = new Fingerprint2011(); diff --git a/guava/src/com/google/common/hash/Funnels.java b/guava/src/com/google/common/hash/Funnels.java index 387cd87f54d2..456dc06522b8 100644 --- a/guava/src/com/google/common/hash/Funnels.java +++ b/guava/src/com/google/common/hash/Funnels.java @@ -15,6 +15,7 @@ package com.google.common.hash; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Preconditions; import java.io.InvalidObjectException; import java.io.ObjectInputStream; @@ -29,6 +30,7 @@ * @author Dimitris Andreou * @since 11.0 */ +@J2ktIncompatible @Beta public final class Funnels { private Funnels() {} diff --git a/guava/src/com/google/common/hash/HashingInputStream.java b/guava/src/com/google/common/hash/HashingInputStream.java index f49dfd62daa5..5eb7b65b6a60 100644 --- a/guava/src/com/google/common/hash/HashingInputStream.java +++ b/guava/src/com/google/common/hash/HashingInputStream.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.io.FilterInputStream; import java.io.IOException; @@ -28,6 +29,7 @@ * @author Qian Huang * @since 16.0 */ +@J2ktIncompatible @Beta public final class HashingInputStream extends FilterInputStream { private final Hasher hasher; diff --git a/guava/src/com/google/common/hash/HashingOutputStream.java b/guava/src/com/google/common/hash/HashingOutputStream.java index 20f1316a558c..b7aa24a22576 100644 --- a/guava/src/com/google/common/hash/HashingOutputStream.java +++ b/guava/src/com/google/common/hash/HashingOutputStream.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; +import com.google.common.annotations.J2ktIncompatible; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -27,6 +28,7 @@ * @author Zoe Piepmeier * @since 16.0 */ +@J2ktIncompatible @Beta public final class HashingOutputStream extends FilterOutputStream { private final Hasher hasher; diff --git a/guava/src/com/google/common/hash/ImmutableSupplier.java b/guava/src/com/google/common/hash/ImmutableSupplier.java index b6a74a77b719..d8915f0517d5 100644 --- a/guava/src/com/google/common/hash/ImmutableSupplier.java +++ b/guava/src/com/google/common/hash/ImmutableSupplier.java @@ -14,6 +14,7 @@ package com.google.common.hash; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.base.Supplier; import com.google.errorprone.annotations.Immutable; @@ -22,5 +23,6 @@ * Immutable}. */ // TODO(cpovirk): Should we just use ChecksumType directly instead of defining this type? +@J2ktIncompatible @Immutable interface ImmutableSupplier extends Supplier {} diff --git a/guava/src/com/google/common/hash/MacHashFunction.java b/guava/src/com/google/common/hash/MacHashFunction.java index 390b49c30234..b5b7196e3370 100644 --- a/guava/src/com/google/common/hash/MacHashFunction.java +++ b/guava/src/com/google/common/hash/MacHashFunction.java @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.nio.ByteBuffer; import java.security.InvalidKeyException; @@ -29,6 +30,7 @@ * * @author Kurt Alfred Kluever */ +@J2ktIncompatible @Immutable final class MacHashFunction extends AbstractHashFunction { diff --git a/guava/src/com/google/common/hash/Murmur3_128HashFunction.java b/guava/src/com/google/common/hash/Murmur3_128HashFunction.java index eadce8c1d244..1469d45e77e8 100644 --- a/guava/src/com/google/common/hash/Murmur3_128HashFunction.java +++ b/guava/src/com/google/common/hash/Murmur3_128HashFunction.java @@ -28,6 +28,7 @@ import static com.google.common.hash.Hashing.GOOD_FAST_HASH_SEED; import static java.lang.Byte.toUnsignedInt; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.io.Serializable; import java.nio.ByteBuffer; @@ -41,6 +42,7 @@ * @author Austin Appleby * @author Dimitris Andreou */ +@J2ktIncompatible @Immutable @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_128HashFunction extends AbstractHashFunction implements Serializable { diff --git a/guava/src/com/google/common/hash/Murmur3_32HashFunction.java b/guava/src/com/google/common/hash/Murmur3_32HashFunction.java index a2b206b127cb..bf092be106e8 100644 --- a/guava/src/com/google/common/hash/Murmur3_32HashFunction.java +++ b/guava/src/com/google/common/hash/Murmur3_32HashFunction.java @@ -31,6 +31,7 @@ import static java.lang.Byte.toUnsignedInt; import static java.nio.charset.StandardCharsets.UTF_8; +import com.google.common.annotations.J2ktIncompatible; import com.google.common.primitives.Chars; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; @@ -51,6 +52,7 @@ * @author Dimitris Andreou * @author Kurt Alfred Kluever */ +@J2ktIncompatible @Immutable @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_32HashFunction extends AbstractHashFunction implements Serializable { diff --git a/guava/src/com/google/common/hash/SipHashFunction.java b/guava/src/com/google/common/hash/SipHashFunction.java index a5f328c3f3fc..fc0ef8baaa55 100644 --- a/guava/src/com/google/common/hash/SipHashFunction.java +++ b/guava/src/com/google/common/hash/SipHashFunction.java @@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.annotations.J2ktIncompatible; import com.google.errorprone.annotations.Immutable; import java.io.Serializable; import java.nio.ByteBuffer; @@ -33,6 +34,7 @@ * @author Jean-Philippe Aumasson * @author Daniel J. Bernstein */ +@J2ktIncompatible @Immutable final class SipHashFunction extends AbstractHashFunction implements Serializable { static final HashFunction SIP_HASH_24 =