aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpovirk <cpovirk@google.com>2023-11-30 13:51:24 -0800
committerGoogle Java Core Libraries <jake-team+copybara@google.com>2023-11-30 13:54:06 -0800
commitf4c1264c9f8ee1e72af39c4fa3776b86b8519ed1 (patch)
treef36ec944382abe068663becf983b1fd87f01252d
parentb252447ec28e076362358782d390cb0b7871a5ab (diff)
downloadguava-f4c1264c9f8ee1e72af39c4fa3776b86b8519ed1.tar.gz
Declare "redundant" overrides of all our package-private `writeReplace` methods.
If users request for an optimizer to keep one of our classes in `com.google.common.collect` but permit it to move supertypes or subtypes of that class into other packages, then those `writeReplace` methods are no longer treated as overrides, and serialization breaks. Normally, optimizers are smart enough not to break overrides. However, in the case of serialization, `writeReplace` is invoked reflectively inside the serialization system, which also performs its own access checks. This means that some optimizers don't know that `writeReplace` is called. So, even if they are instructed to keep all methods of that name, they don't know to preserve their override-ness. In the particular case we were seeing, `ImmutableCollection` and `RegularImmutableList` were ending up in the default package, while `ImmutableList` was staying in `common.collect`. That might sound like it should still work: Serializing an `RegularImmutableList` instance should invoke the package-private `ImmutableCollection.writeReplace` method. However, if I'm understanding correctly, Java serialization is buggy (or at least surprising relative to normal inheritance): `ObjectStreamClass.getInheritableMethod`, upon finding the package-private `ImmutableList.writeReplace` method (which is _not_ relevant to `RegularImmutableList` anymore because it now appears in a different package), [gives up on looking for `writeReplace`](https://github.com/openjdk/jdk/blob/570dffb104fc37f053fcdf38a24aa2cabdc921c0/src/java.base/share/classes/java/io/ObjectStreamClass.java#L1518) instead of continuing to scan for `writeReplace` in any grandparent+ types that live in the same package. RELNOTES=n/a PiperOrigin-RevId: 586777576
-rw-r--r--android/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java118
-rw-r--r--android/guava/src/com/google/common/collect/CartesianList.java11
-rw-r--r--android/guava/src/com/google/common/collect/ContiguousSet.java10
-rw-r--r--android/guava/src/com/google/common/collect/DenseImmutableTable.java51
-rw-r--r--android/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java9
-rw-r--r--android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java9
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableCollection.java2
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableList.java20
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableMap.java28
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableMapEntrySet.java9
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableMapKeySet.java3
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableMapValues.java9
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableMultimap.java18
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableRangeMap.java16
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableRangeSet.java17
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableSetMultimap.java9
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableSortedMap.java19
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableTable.java9
-rw-r--r--android/guava/src/com/google/common/collect/IndexedImmutableSet.java19
-rw-r--r--android/guava/src/com/google/common/collect/Lists.java9
-rw-r--r--android/guava/src/com/google/common/collect/RegularContiguousSet.java9
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableAsList.java10
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableBiMap.java11
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableList.java11
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableMap.java43
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableMultiset.java13
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableSet.java11
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java9
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java10
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableTable.java26
-rw-r--r--android/guava/src/com/google/common/collect/Sets.java9
-rw-r--r--android/guava/src/com/google/common/collect/SingletonImmutableSet.java11
-rw-r--r--android/guava/src/com/google/common/collect/SingletonImmutableTable.java6
-rw-r--r--android/guava/src/com/google/common/collect/SparseImmutableTable.java6
-rw-r--r--guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java118
-rw-r--r--guava/src/com/google/common/collect/CartesianList.java11
-rw-r--r--guava/src/com/google/common/collect/ContiguousSet.java10
-rw-r--r--guava/src/com/google/common/collect/DenseImmutableTable.java51
-rw-r--r--guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java9
-rw-r--r--guava/src/com/google/common/collect/DescendingImmutableSortedSet.java9
-rw-r--r--guava/src/com/google/common/collect/ImmutableCollection.java2
-rw-r--r--guava/src/com/google/common/collect/ImmutableList.java20
-rw-r--r--guava/src/com/google/common/collect/ImmutableMap.java28
-rw-r--r--guava/src/com/google/common/collect/ImmutableMapEntrySet.java9
-rw-r--r--guava/src/com/google/common/collect/ImmutableMapKeySet.java9
-rw-r--r--guava/src/com/google/common/collect/ImmutableMapValues.java18
-rw-r--r--guava/src/com/google/common/collect/ImmutableMultimap.java18
-rw-r--r--guava/src/com/google/common/collect/ImmutableMultiset.java9
-rw-r--r--guava/src/com/google/common/collect/ImmutableRangeMap.java16
-rw-r--r--guava/src/com/google/common/collect/ImmutableRangeSet.java17
-rw-r--r--guava/src/com/google/common/collect/ImmutableSet.java28
-rw-r--r--guava/src/com/google/common/collect/ImmutableSetMultimap.java9
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedAsList.java10
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedMap.java19
-rw-r--r--guava/src/com/google/common/collect/ImmutableTable.java9
-rw-r--r--guava/src/com/google/common/collect/IndexedImmutableSet.java19
-rw-r--r--guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java20
-rw-r--r--guava/src/com/google/common/collect/JdkBackedImmutableMap.java11
-rw-r--r--guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java11
-rw-r--r--guava/src/com/google/common/collect/JdkBackedImmutableSet.java11
-rw-r--r--guava/src/com/google/common/collect/Lists.java9
-rw-r--r--guava/src/com/google/common/collect/RegularContiguousSet.java9
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableAsList.java10
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableBiMap.java29
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableList.java11
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableMap.java27
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableMultiset.java11
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableSet.java11
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java9
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableSortedSet.java10
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableTable.java26
-rw-r--r--guava/src/com/google/common/collect/Sets.java9
-rw-r--r--guava/src/com/google/common/collect/SingletonImmutableBiMap.java11
-rw-r--r--guava/src/com/google/common/collect/SingletonImmutableList.java11
-rw-r--r--guava/src/com/google/common/collect/SingletonImmutableSet.java11
-rw-r--r--guava/src/com/google/common/collect/SingletonImmutableTable.java6
-rw-r--r--guava/src/com/google/common/collect/SparseImmutableTable.java6
77 files changed, 1277 insertions, 20 deletions
diff --git a/android/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java b/android/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java
new file mode 100644
index 000000000..bf10f5f75
--- /dev/null
+++ b/android/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2023 The Guava Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.common.collect;
+
+import static com.google.common.truth.Truth.assertWithMessage;
+import static java.lang.reflect.Modifier.PRIVATE;
+import static java.lang.reflect.Modifier.PROTECTED;
+import static java.lang.reflect.Modifier.PUBLIC;
+import static java.util.Arrays.asList;
+
+import com.google.common.base.Optional;
+import com.google.common.reflect.ClassPath;
+import com.google.common.reflect.ClassPath.ClassInfo;
+import com.google.common.reflect.TypeToken;
+import java.lang.reflect.Method;
+import junit.framework.TestCase;
+
+/**
+ * Tests that all package-private {@code writeReplace} methods are overridden in any existing
+ * subclasses. Without such overrides, optimizers might put a {@code writeReplace}-containing class
+ * and its subclass in different packages, causing the serialization system to fail to invoke {@code
+ * writeReplace} when serializing an instance of the subclass. For an example of this problem, see
+ * b/310253115.
+ */
+public class WriteReplaceOverridesTest extends TestCase {
+ private static final ImmutableSet<String> GUAVA_PACKAGES =
+ FluentIterable.of(
+ "base",
+ "cache",
+ "collect",
+ "escape",
+ "eventbus",
+ "graph",
+ "hash",
+ "html",
+ "io",
+ "math",
+ "net",
+ "primitives",
+ "reflect",
+ "util.concurrent",
+ "xml")
+ .transform("com.google.common."::concat)
+ .toSet();
+
+ public void testClassesHaveOverrides() throws Exception {
+ for (ClassInfo info : ClassPath.from(getClass().getClassLoader()).getAllClasses()) {
+ if (!GUAVA_PACKAGES.contains(info.getPackageName())) {
+ continue;
+ }
+ if (info.getName().endsWith("GwtSerializationDependencies")) {
+ continue; // These classes exist only for the GWT compiler, not to be used.
+ }
+ if (
+ /*
+ * At least one of the classes nested inside TypeResolverTest triggers a bug under older JDKs:
+ * https://bugs.openjdk.org/browse/JDK-8215328 -> https://bugs.openjdk.org/browse/JDK-8215470
+ * https://github.com/google/guava/blob/4f12c5891a7adedbaa1d99fc9f77d8cc4e9da206/guava-tests/test/com/google/common/reflect/TypeResolverTest.java#L201
+ */
+ info.getName().contains("TypeResolverTest")
+ /*
+ * And at least one of the classes inside TypeTokenTest ends up with a null value in
+ * TypeMappingIntrospector.mappings. That happens only under older JDKs, too, so it may
+ * well be a JDK bug.
+ */
+ || info.getName().contains("TypeTokenTest")
+ /*
+ * Luckily, we don't care about analyzing tests at all. We'd skip them all if we could do so
+ * trivially, but it's enough to skip these ones.
+ */
+ ) {
+ continue;
+ }
+ Class<?> clazz = info.load();
+ try {
+ Method unused = clazz.getDeclaredMethod("writeReplace");
+ continue; // It overrides writeReplace, so it's safe.
+ } catch (NoSuchMethodException e) {
+ // This is a class whose supertypes we want to examine. We'll do that below.
+ }
+ Optional<Class<?>> supersWithPackagePrivateWriteReplace =
+ FluentIterable.from(TypeToken.of(clazz).getTypes())
+ .transform(TypeToken::getRawType)
+ .transformAndConcat(c -> asList(c.getDeclaredMethods()))
+ .firstMatch(
+ m ->
+ m.getName().equals("writeReplace")
+ && m.getParameterTypes().length == 0
+ // Only package-private methods are a problem.
+ && (m.getModifiers() & (PUBLIC | PROTECTED | PRIVATE)) == 0)
+ .transform(Method::getDeclaringClass);
+ if (!supersWithPackagePrivateWriteReplace.isPresent()) {
+ continue;
+ }
+ assertWithMessage(
+ "To help optimizers, any class that inherits a package-private writeReplace() method"
+ + " should override that method.\n"
+ + "(An override that delegates to the supermethod is fine.)\n"
+ + "%s has no such override despite inheriting writeReplace() from %s",
+ clazz.getName(), supersWithPackagePrivateWriteReplace.get().getName())
+ .fail();
+ }
+ }
+}
diff --git a/android/guava/src/com/google/common/collect/CartesianList.java b/android/guava/src/com/google/common/collect/CartesianList.java
index 4c31b1299..a93fb032f 100644
--- a/android/guava/src/com/google/common/collect/CartesianList.java
+++ b/android/guava/src/com/google/common/collect/CartesianList.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkElementIndex;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.math.IntMath;
import java.util.AbstractList;
import java.util.List;
@@ -132,6 +134,15 @@ final class CartesianList<E> extends AbstractList<List<E>> implements RandomAcce
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @J2ktIncompatible // serialization
+ @Override
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
diff --git a/android/guava/src/com/google/common/collect/ContiguousSet.java b/android/guava/src/com/google/common/collect/ContiguousSet.java
index d0792054e..539c67383 100644
--- a/android/guava/src/com/google/common/collect/ContiguousSet.java
+++ b/android/guava/src/com/google/common/collect/ContiguousSet.java
@@ -20,6 +20,7 @@ import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.DoNotCall;
import java.util.Collections;
import java.util.NoSuchElementException;
@@ -259,4 +260,13 @@ public abstract class ContiguousSet<C extends Comparable> extends ImmutableSorte
public static <E> ImmutableSortedSet.Builder<E> builder() {
throw new UnsupportedOperationException();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @J2ktIncompatible // serialization
+ @Override
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/DenseImmutableTable.java b/android/guava/src/com/google/common/collect/DenseImmutableTable.java
index 9de77c57f..a8e96e382 100644
--- a/android/guava/src/com/google/common/collect/DenseImmutableTable.java
+++ b/android/guava/src/com/google/common/collect/DenseImmutableTable.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap;
import com.google.errorprone.annotations.Immutable;
import com.google.j2objc.annotations.WeakOuter;
@@ -144,6 +146,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
}
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @J2ktIncompatible // serialization
+ @Override
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private final class Row extends ImmutableArrayMap<C, V> {
@@ -169,6 +180,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private final class Column extends ImmutableArrayMap<R, V> {
@@ -194,6 +214,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@WeakOuter
@@ -216,6 +245,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@WeakOuter
@@ -238,6 +276,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -285,7 +332,9 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
}
@Override
- SerializedForm createSerializedForm() {
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
return SerializedForm.create(this, cellRowIndices, cellColumnIndices);
}
}
diff --git a/android/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java b/android/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java
index 181731cc4..931c3e72c 100644
--- a/android/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java
+++ b/android/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java
@@ -15,6 +15,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import javax.annotation.CheckForNull;
/**
@@ -83,4 +84,12 @@ final class DescendingImmutableSortedMultiset<E> extends ImmutableSortedMultiset
boolean isPartialView() {
return forward.isPartialView();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
index 88c7d6b5c..10b3fa866 100644
--- a/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
+++ b/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
@@ -17,6 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import javax.annotation.CheckForNull;
/**
@@ -121,4 +122,12 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
boolean isPartialView() {
return forward.isPartialView();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableCollection.java b/android/guava/src/com/google/common/collect/ImmutableCollection.java
index 1a41d55ef..c8167e8f6 100644
--- a/android/guava/src/com/google/common/collect/ImmutableCollection.java
+++ b/android/guava/src/com/google/common/collect/ImmutableCollection.java
@@ -21,6 +21,7 @@ import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static com.google.common.collect.ObjectArrays.checkElementsNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
@@ -381,6 +382,7 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple
}
@J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
// We serialize by default to ImmutableList, the simplest thing that works.
return new ImmutableList.SerializedForm(toArray());
diff --git a/android/guava/src/com/google/common/collect/ImmutableList.java b/android/guava/src/com/google/common/collect/ImmutableList.java
index d28c051c4..9bf354580 100644
--- a/android/guava/src/com/google/common/collect/ImmutableList.java
+++ b/android/guava/src/com/google/common/collect/ImmutableList.java
@@ -26,6 +26,7 @@ import static com.google.common.collect.ObjectArrays.checkElementsNotNull;
import static com.google.common.collect.RegularImmutableList.EMPTY;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
@@ -489,6 +490,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
/**
@@ -638,6 +648,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
boolean isPartialView() {
return forwardList.isPartialView();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -684,6 +703,7 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
@Override
@J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
return new SerializedForm(toArray());
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableMap.java b/android/guava/src/com/google/common/collect/ImmutableMap.java
index 59742c601..4ec2f834e 100644
--- a/android/guava/src/com/google/common/collect/ImmutableMap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableMap.java
@@ -23,6 +23,7 @@ import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
@@ -727,6 +728,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
public UnmodifiableIterator<Entry<K, V>> iterator() {
return entryIterator();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
return new EntrySetImpl();
}
@@ -735,6 +745,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
ImmutableCollection<V> createValues() {
return new ImmutableMapValues<>(this);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
ImmutableMap() {}
@@ -1016,6 +1035,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
}
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
diff --git a/android/guava/src/com/google/common/collect/ImmutableMapEntrySet.java b/android/guava/src/com/google/common/collect/ImmutableMapEntrySet.java
index 3732e2dfe..27a4c2c33 100644
--- a/android/guava/src/com/google/common/collect/ImmutableMapEntrySet.java
+++ b/android/guava/src/com/google/common/collect/ImmutableMapEntrySet.java
@@ -68,6 +68,15 @@ abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
ImmutableList<Entry<K, V>> createAsList() {
return entries;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
ImmutableMapEntrySet() {}
diff --git a/android/guava/src/com/google/common/collect/ImmutableMapKeySet.java b/android/guava/src/com/google/common/collect/ImmutableMapKeySet.java
index 056a35141..cd9f4accf 100644
--- a/android/guava/src/com/google/common/collect/ImmutableMapKeySet.java
+++ b/android/guava/src/com/google/common/collect/ImmutableMapKeySet.java
@@ -62,8 +62,9 @@ final class ImmutableMapKeySet<K, V> extends IndexedImmutableSet<K> {
return true;
}
- @GwtIncompatible // serialization
@Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
return new KeySetSerializedForm<K>(map);
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableMapValues.java b/android/guava/src/com/google/common/collect/ImmutableMapValues.java
index ba868d1b9..0ddf84ffe 100644
--- a/android/guava/src/com/google/common/collect/ImmutableMapValues.java
+++ b/android/guava/src/com/google/common/collect/ImmutableMapValues.java
@@ -88,6 +88,15 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
public int size() {
return entryList.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableMultimap.java b/android/guava/src/com/google/common/collect/ImmutableMultimap.java
index e4ad391f5..597d0be27 100644
--- a/android/guava/src/com/google/common/collect/ImmutableMultimap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableMultimap.java
@@ -576,6 +576,15 @@ public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V
return false;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
private static final long serialVersionUID = 0;
}
@@ -757,6 +766,15 @@ public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V
return true;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
@J2ktIncompatible // serialization
private static final long serialVersionUID = 0;
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableRangeMap.java b/android/guava/src/com/google/common/collect/ImmutableRangeMap.java
index 710c8916e..532631617 100644
--- a/android/guava/src/com/google/common/collect/ImmutableRangeMap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableRangeMap.java
@@ -339,6 +339,14 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
final ImmutableRangeMap<K, V> outer = this;
return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
@@ -350,6 +358,14 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K
return ImmutableRangeMap.of();
}
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableRangeSet.java b/android/guava/src/com/google/common/collect/ImmutableRangeSet.java
index 844c1c1dc..d1f05bc98 100644
--- a/android/guava/src/com/google/common/collect/ImmutableRangeSet.java
+++ b/android/guava/src/com/google/common/collect/ImmutableRangeSet.java
@@ -355,6 +355,14 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -474,6 +482,15 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableSetMultimap.java b/android/guava/src/com/google/common/collect/ImmutableSetMultimap.java
index b0039636a..b2d80af4f 100644
--- a/android/guava/src/com/google/common/collect/ImmutableSetMultimap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableSetMultimap.java
@@ -468,6 +468,15 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V>
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private static <V> ImmutableSet<V> valueSet(
diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedMap.java b/android/guava/src/com/google/common/collect/ImmutableSortedMap.java
index 60e673669..2bebbe59f 100644
--- a/android/guava/src/com/google/common/collect/ImmutableSortedMap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableSortedMap.java
@@ -23,6 +23,7 @@ import static com.google.common.collect.Maps.keyOrNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
@@ -823,6 +824,15 @@ public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V>
public int size() {
return ImmutableSortedMap.this.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
@@ -830,6 +840,15 @@ public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V>
ImmutableMap<K, V> map() {
return ImmutableSortedMap.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
return isEmpty() ? ImmutableSet.<Entry<K, V>>of() : new EntrySet();
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableTable.java b/android/guava/src/com/google/common/collect/ImmutableTable.java
index 9c45e361f..6c8f26dfe 100644
--- a/android/guava/src/com/google/common/collect/ImmutableTable.java
+++ b/android/guava/src/com/google/common/collect/ImmutableTable.java
@@ -396,9 +396,6 @@ public abstract class ImmutableTable<R, C, V> extends AbstractTable<R, C, V>
throw new UnsupportedOperationException();
}
- /** Creates the common serialized form for this table. */
- abstract SerializedForm createSerializedForm();
-
/**
* Serialized type for all ImmutableTable instances. It captures the logical contents and
* preserves iteration order of all views.
@@ -454,9 +451,9 @@ public abstract class ImmutableTable<R, C, V> extends AbstractTable<R, C, V>
private static final long serialVersionUID = 0;
}
- final Object writeReplace() {
- return createSerializedForm();
- }
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ abstract Object writeReplace();
@GwtIncompatible // serialization
@J2ktIncompatible
diff --git a/android/guava/src/com/google/common/collect/IndexedImmutableSet.java b/android/guava/src/com/google/common/collect/IndexedImmutableSet.java
index 25aae94e8..805f15bec 100644
--- a/android/guava/src/com/google/common/collect/IndexedImmutableSet.java
+++ b/android/guava/src/com/google/common/collect/IndexedImmutableSet.java
@@ -18,6 +18,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import org.checkerframework.checker.nullness.qual.Nullable;
@GwtCompatible(emulated = true)
@@ -53,6 +54,24 @@ abstract class IndexedImmutableSet<E> extends ImmutableSet<E> {
public int size() {
return IndexedImmutableSet.this.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/Lists.java b/android/guava/src/com/google/common/collect/Lists.java
index 047575b57..e59f60aae 100644
--- a/android/guava/src/com/google/common/collect/Lists.java
+++ b/android/guava/src/com/google/common/collect/Lists.java
@@ -766,6 +766,15 @@ public final class Lists {
public int size() {
return string.length();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private static final class CharSequenceAsList extends AbstractList<Character> {
diff --git a/android/guava/src/com/google/common/collect/RegularContiguousSet.java b/android/guava/src/com/google/common/collect/RegularContiguousSet.java
index 9c2e5a26f..8159d107b 100644
--- a/android/guava/src/com/google/common/collect/RegularContiguousSet.java
+++ b/android/guava/src/com/google/common/collect/RegularContiguousSet.java
@@ -143,6 +143,15 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
checkElementIndex(i, size());
return domain.offset(first(), i);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
} else {
return super.createAsList();
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableAsList.java b/android/guava/src/com/google/common/collect/RegularImmutableAsList.java
index e344db1ea..928506e44 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableAsList.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableAsList.java
@@ -18,6 +18,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -89,4 +90,13 @@ class RegularImmutableAsList<E> extends ImmutableAsList<E> {
public E get(int index) {
return delegateList.get(index);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableBiMap.java b/android/guava/src/com/google/common/collect/RegularImmutableBiMap.java
index 2ee752ceb..0188e6367 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableBiMap.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableBiMap.java
@@ -17,6 +17,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -120,4 +122,13 @@ final class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableList.java b/android/guava/src/com/google/common/collect/RegularImmutableList.java
index baf1d66ed..e7aedc972 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableList.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableList.java
@@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkElementIndex;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -85,4 +87,13 @@ class RegularImmutableList<E> extends ImmutableList<E> {
}
// TODO(lowasser): benchmark optimizations for equals() and see if they're worthwhile
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableMap.java b/android/guava/src/com/google/common/collect/RegularImmutableMap.java
index d6d214b65..100e06129 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableMap.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableMap.java
@@ -22,6 +22,7 @@ import static com.google.common.collect.CollectPreconditions.checkEntryNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import java.util.AbstractMap;
@@ -435,6 +436,14 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
public boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
@@ -458,6 +467,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
public int size() {
return size;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -495,6 +513,13 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
public int size() {
return size;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
static final class KeySet<K> extends ImmutableSet<K> {
@@ -535,6 +560,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
public int size() {
return map.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@SuppressWarnings("unchecked")
@@ -548,6 +582,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
return false;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
// This class is never actually serialized directly, but we have to make the
// warning go away (and suppressing would suppress for all nested classes too)
@J2ktIncompatible // serialization
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableMultiset.java b/android/guava/src/com/google/common/collect/RegularImmutableMultiset.java
index 6fbc099c8..0e59465ad 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableMultiset.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableMultiset.java
@@ -16,6 +16,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.collect.Multiset.Entry;
import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.concurrent.LazyInit;
@@ -93,6 +94,15 @@ class RegularImmutableMultiset<E> extends ImmutableMultiset<E> {
public int size() {
return contents.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -130,8 +140,9 @@ class RegularImmutableMultiset<E> extends ImmutableMultiset<E> {
private static final long serialVersionUID = 0;
}
- @GwtIncompatible
@Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
return new SerializedForm(this);
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableSet.java b/android/guava/src/com/google/common/collect/RegularImmutableSet.java
index 2382ef62e..790aa6453 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableSet.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableSet.java
@@ -17,6 +17,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -120,4 +122,13 @@ final class RegularImmutableSet<E> extends ImmutableSet<E> {
boolean isHashCodeFast() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java b/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
index 3b6d79c44..1ece0a0a9 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkPositionIndexes;
import static com.google.common.collect.BoundType.CLOSED;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Ints;
import java.util.Comparator;
@@ -124,4 +125,12 @@ final class RegularImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E>
boolean isPartialView() {
return offset > 0 || length < cumulativeCounts.length - 1;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
index ef0fbb378..d31572cf7 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import java.util.Collection;
import java.util.Collections;
@@ -319,4 +320,13 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
? emptySet(reversedOrder)
: new RegularImmutableSortedSet<E>(elements.reverse(), reversedOrder);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableTable.java b/android/guava/src/com/google/common/collect/RegularImmutableTable.java
index 337f123b6..03def2cbc 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableTable.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableTable.java
@@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.j2objc.annotations.WeakOuter;
import java.util.Collections;
import java.util.Comparator;
@@ -69,6 +71,15 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
abstract V getValue(int iterationIndex);
@@ -94,6 +105,15 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
static <R, C, V> RegularImmutableTable<R, C, V> forCells(
@@ -181,4 +201,10 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
newValue,
existingValue);
}
+
+ // redeclare to satisfy our test for b/310253115
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ abstract Object writeReplace();
}
diff --git a/android/guava/src/com/google/common/collect/Sets.java b/android/guava/src/com/google/common/collect/Sets.java
index a31980559..cbea9ca32 100644
--- a/android/guava/src/com/google/common/collect/Sets.java
+++ b/android/guava/src/com/google/common/collect/Sets.java
@@ -1374,6 +1374,15 @@ public final class Sets {
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
return new CartesianSet<E>(axes, new CartesianList<E>(listAxes));
}
diff --git a/android/guava/src/com/google/common/collect/SingletonImmutableSet.java b/android/guava/src/com/google/common/collect/SingletonImmutableSet.java
index 088cb802f..15db1c5e5 100644
--- a/android/guava/src/com/google/common/collect/SingletonImmutableSet.java
+++ b/android/guava/src/com/google/common/collect/SingletonImmutableSet.java
@@ -17,6 +17,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Preconditions;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -80,4 +82,13 @@ final class SingletonImmutableSet<E> extends ImmutableSet<E> {
public String toString() {
return '[' + element.toString() + ']';
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/android/guava/src/com/google/common/collect/SingletonImmutableTable.java b/android/guava/src/com/google/common/collect/SingletonImmutableTable.java
index cfaeadb41..6f839ceb4 100644
--- a/android/guava/src/com/google/common/collect/SingletonImmutableTable.java
+++ b/android/guava/src/com/google/common/collect/SingletonImmutableTable.java
@@ -19,6 +19,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.Map;
/**
@@ -77,7 +79,9 @@ class SingletonImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
}
@Override
- SerializedForm createSerializedForm() {
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
return SerializedForm.create(this, new int[] {0}, new int[] {0});
}
}
diff --git a/android/guava/src/com/google/common/collect/SparseImmutableTable.java b/android/guava/src/com/google/common/collect/SparseImmutableTable.java
index 44881fde7..f7222b120 100644
--- a/android/guava/src/com/google/common/collect/SparseImmutableTable.java
+++ b/android/guava/src/com/google/common/collect/SparseImmutableTable.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.Immutable;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -130,7 +132,9 @@ final class SparseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
}
@Override
- SerializedForm createSerializedForm() {
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
Map<C, Integer> columnKeyToIndex = Maps.indexMap(columnKeySet());
int[] cellColumnIndices = new int[cellSet().size()];
int i = 0;
diff --git a/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java b/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java
new file mode 100644
index 000000000..bf10f5f75
--- /dev/null
+++ b/guava-tests/test/com/google/common/collect/WriteReplaceOverridesTest.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2023 The Guava Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.common.collect;
+
+import static com.google.common.truth.Truth.assertWithMessage;
+import static java.lang.reflect.Modifier.PRIVATE;
+import static java.lang.reflect.Modifier.PROTECTED;
+import static java.lang.reflect.Modifier.PUBLIC;
+import static java.util.Arrays.asList;
+
+import com.google.common.base.Optional;
+import com.google.common.reflect.ClassPath;
+import com.google.common.reflect.ClassPath.ClassInfo;
+import com.google.common.reflect.TypeToken;
+import java.lang.reflect.Method;
+import junit.framework.TestCase;
+
+/**
+ * Tests that all package-private {@code writeReplace} methods are overridden in any existing
+ * subclasses. Without such overrides, optimizers might put a {@code writeReplace}-containing class
+ * and its subclass in different packages, causing the serialization system to fail to invoke {@code
+ * writeReplace} when serializing an instance of the subclass. For an example of this problem, see
+ * b/310253115.
+ */
+public class WriteReplaceOverridesTest extends TestCase {
+ private static final ImmutableSet<String> GUAVA_PACKAGES =
+ FluentIterable.of(
+ "base",
+ "cache",
+ "collect",
+ "escape",
+ "eventbus",
+ "graph",
+ "hash",
+ "html",
+ "io",
+ "math",
+ "net",
+ "primitives",
+ "reflect",
+ "util.concurrent",
+ "xml")
+ .transform("com.google.common."::concat)
+ .toSet();
+
+ public void testClassesHaveOverrides() throws Exception {
+ for (ClassInfo info : ClassPath.from(getClass().getClassLoader()).getAllClasses()) {
+ if (!GUAVA_PACKAGES.contains(info.getPackageName())) {
+ continue;
+ }
+ if (info.getName().endsWith("GwtSerializationDependencies")) {
+ continue; // These classes exist only for the GWT compiler, not to be used.
+ }
+ if (
+ /*
+ * At least one of the classes nested inside TypeResolverTest triggers a bug under older JDKs:
+ * https://bugs.openjdk.org/browse/JDK-8215328 -> https://bugs.openjdk.org/browse/JDK-8215470
+ * https://github.com/google/guava/blob/4f12c5891a7adedbaa1d99fc9f77d8cc4e9da206/guava-tests/test/com/google/common/reflect/TypeResolverTest.java#L201
+ */
+ info.getName().contains("TypeResolverTest")
+ /*
+ * And at least one of the classes inside TypeTokenTest ends up with a null value in
+ * TypeMappingIntrospector.mappings. That happens only under older JDKs, too, so it may
+ * well be a JDK bug.
+ */
+ || info.getName().contains("TypeTokenTest")
+ /*
+ * Luckily, we don't care about analyzing tests at all. We'd skip them all if we could do so
+ * trivially, but it's enough to skip these ones.
+ */
+ ) {
+ continue;
+ }
+ Class<?> clazz = info.load();
+ try {
+ Method unused = clazz.getDeclaredMethod("writeReplace");
+ continue; // It overrides writeReplace, so it's safe.
+ } catch (NoSuchMethodException e) {
+ // This is a class whose supertypes we want to examine. We'll do that below.
+ }
+ Optional<Class<?>> supersWithPackagePrivateWriteReplace =
+ FluentIterable.from(TypeToken.of(clazz).getTypes())
+ .transform(TypeToken::getRawType)
+ .transformAndConcat(c -> asList(c.getDeclaredMethods()))
+ .firstMatch(
+ m ->
+ m.getName().equals("writeReplace")
+ && m.getParameterTypes().length == 0
+ // Only package-private methods are a problem.
+ && (m.getModifiers() & (PUBLIC | PROTECTED | PRIVATE)) == 0)
+ .transform(Method::getDeclaringClass);
+ if (!supersWithPackagePrivateWriteReplace.isPresent()) {
+ continue;
+ }
+ assertWithMessage(
+ "To help optimizers, any class that inherits a package-private writeReplace() method"
+ + " should override that method.\n"
+ + "(An override that delegates to the supermethod is fine.)\n"
+ + "%s has no such override despite inheriting writeReplace() from %s",
+ clazz.getName(), supersWithPackagePrivateWriteReplace.get().getName())
+ .fail();
+ }
+ }
+}
diff --git a/guava/src/com/google/common/collect/CartesianList.java b/guava/src/com/google/common/collect/CartesianList.java
index 4c31b1299..a93fb032f 100644
--- a/guava/src/com/google/common/collect/CartesianList.java
+++ b/guava/src/com/google/common/collect/CartesianList.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkElementIndex;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.math.IntMath;
import java.util.AbstractList;
import java.util.List;
@@ -132,6 +134,15 @@ final class CartesianList<E> extends AbstractList<List<E>> implements RandomAcce
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @J2ktIncompatible // serialization
+ @Override
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
diff --git a/guava/src/com/google/common/collect/ContiguousSet.java b/guava/src/com/google/common/collect/ContiguousSet.java
index d0792054e..539c67383 100644
--- a/guava/src/com/google/common/collect/ContiguousSet.java
+++ b/guava/src/com/google/common/collect/ContiguousSet.java
@@ -20,6 +20,7 @@ import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.DoNotCall;
import java.util.Collections;
import java.util.NoSuchElementException;
@@ -259,4 +260,13 @@ public abstract class ContiguousSet<C extends Comparable> extends ImmutableSorte
public static <E> ImmutableSortedSet.Builder<E> builder() {
throw new UnsupportedOperationException();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @J2ktIncompatible // serialization
+ @Override
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/DenseImmutableTable.java b/guava/src/com/google/common/collect/DenseImmutableTable.java
index 9de77c57f..a8e96e382 100644
--- a/guava/src/com/google/common/collect/DenseImmutableTable.java
+++ b/guava/src/com/google/common/collect/DenseImmutableTable.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.collect.ImmutableMap.IteratorBasedImmutableMap;
import com.google.errorprone.annotations.Immutable;
import com.google.j2objc.annotations.WeakOuter;
@@ -144,6 +146,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
}
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @J2ktIncompatible // serialization
+ @Override
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private final class Row extends ImmutableArrayMap<C, V> {
@@ -169,6 +180,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private final class Column extends ImmutableArrayMap<R, V> {
@@ -194,6 +214,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@WeakOuter
@@ -216,6 +245,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@WeakOuter
@@ -238,6 +276,15 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -285,7 +332,9 @@ final class DenseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
}
@Override
- SerializedForm createSerializedForm() {
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
return SerializedForm.create(this, cellRowIndices, cellColumnIndices);
}
}
diff --git a/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java b/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java
index 181731cc4..931c3e72c 100644
--- a/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java
+++ b/guava/src/com/google/common/collect/DescendingImmutableSortedMultiset.java
@@ -15,6 +15,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import javax.annotation.CheckForNull;
/**
@@ -83,4 +84,12 @@ final class DescendingImmutableSortedMultiset<E> extends ImmutableSortedMultiset
boolean isPartialView() {
return forward.isPartialView();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
index 88c7d6b5c..10b3fa866 100644
--- a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
+++ b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
@@ -17,6 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import javax.annotation.CheckForNull;
/**
@@ -121,4 +122,12 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
boolean isPartialView() {
return forward.isPartialView();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/ImmutableCollection.java b/guava/src/com/google/common/collect/ImmutableCollection.java
index 25b62864b..ee18f0d9c 100644
--- a/guava/src/com/google/common/collect/ImmutableCollection.java
+++ b/guava/src/com/google/common/collect/ImmutableCollection.java
@@ -19,6 +19,7 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
@@ -392,6 +393,7 @@ public abstract class ImmutableCollection<E> extends AbstractCollection<E> imple
}
@J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
// We serialize by default to ImmutableList, the simplest thing that works.
return new ImmutableList.SerializedForm(toArray());
diff --git a/guava/src/com/google/common/collect/ImmutableList.java b/guava/src/com/google/common/collect/ImmutableList.java
index 5caa3186a..7c7801dbc 100644
--- a/guava/src/com/google/common/collect/ImmutableList.java
+++ b/guava/src/com/google/common/collect/ImmutableList.java
@@ -26,6 +26,7 @@ import static com.google.common.collect.RegularImmutableList.EMPTY;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -504,6 +505,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
/**
@@ -684,6 +694,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
boolean isPartialView() {
return forwardList.isPartialView();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -730,6 +749,7 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E>
@Override
@J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
return new SerializedForm(toArray());
}
diff --git a/guava/src/com/google/common/collect/ImmutableMap.java b/guava/src/com/google/common/collect/ImmutableMap.java
index b3a6b1943..7a185b5d3 100644
--- a/guava/src/com/google/common/collect/ImmutableMap.java
+++ b/guava/src/com/google/common/collect/ImmutableMap.java
@@ -23,6 +23,7 @@ import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -757,6 +758,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
public UnmodifiableIterator<Entry<K, V>> iterator() {
return entryIterator();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
return new EntrySetImpl();
}
@@ -765,6 +775,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
ImmutableCollection<V> createValues() {
return new ImmutableMapValues<>(this);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
ImmutableMap() {}
@@ -1170,6 +1189,15 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
}
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
diff --git a/guava/src/com/google/common/collect/ImmutableMapEntrySet.java b/guava/src/com/google/common/collect/ImmutableMapEntrySet.java
index 46df158b0..19f75cbbb 100644
--- a/guava/src/com/google/common/collect/ImmutableMapEntrySet.java
+++ b/guava/src/com/google/common/collect/ImmutableMapEntrySet.java
@@ -80,6 +80,15 @@ abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet.CachingAsList<Ent
ImmutableList<Entry<K, V>> createAsList() {
return new RegularImmutableAsList<>(this, entries);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
ImmutableMapEntrySet() {}
diff --git a/guava/src/com/google/common/collect/ImmutableMapKeySet.java b/guava/src/com/google/common/collect/ImmutableMapKeySet.java
index 6d1b51671..fb2661f47 100644
--- a/guava/src/com/google/common/collect/ImmutableMapKeySet.java
+++ b/guava/src/com/google/common/collect/ImmutableMapKeySet.java
@@ -77,6 +77,15 @@ final class ImmutableMapKeySet<K, V> extends IndexedImmutableSet<K> {
return true;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@J2ktIncompatible
diff --git a/guava/src/com/google/common/collect/ImmutableMapValues.java b/guava/src/com/google/common/collect/ImmutableMapValues.java
index 8884c1af6..831364599 100644
--- a/guava/src/com/google/common/collect/ImmutableMapValues.java
+++ b/guava/src/com/google/common/collect/ImmutableMapValues.java
@@ -92,6 +92,15 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
ImmutableCollection<V> delegateCollection() {
return ImmutableMapValues.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
@@ -102,6 +111,15 @@ final class ImmutableMapValues<K, V> extends ImmutableCollection<V> {
map.forEach((k, v) -> action.accept(v));
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@J2ktIncompatible
diff --git a/guava/src/com/google/common/collect/ImmutableMultimap.java b/guava/src/com/google/common/collect/ImmutableMultimap.java
index f1f654645..02dbd5e67 100644
--- a/guava/src/com/google/common/collect/ImmutableMultimap.java
+++ b/guava/src/com/google/common/collect/ImmutableMultimap.java
@@ -578,6 +578,15 @@ public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V
return false;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
private static final long serialVersionUID = 0;
}
@@ -781,6 +790,15 @@ public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V
return true;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
@J2ktIncompatible // serialization
private static final long serialVersionUID = 0;
}
diff --git a/guava/src/com/google/common/collect/ImmutableMultiset.java b/guava/src/com/google/common/collect/ImmutableMultiset.java
index 76a6eb061..f0197433f 100644
--- a/guava/src/com/google/common/collect/ImmutableMultiset.java
+++ b/guava/src/com/google/common/collect/ImmutableMultiset.java
@@ -630,6 +630,15 @@ public abstract class ImmutableMultiset<E> extends ImmutableMultisetGwtSerializa
public int size() {
return entries.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@J2ktIncompatible
diff --git a/guava/src/com/google/common/collect/ImmutableRangeMap.java b/guava/src/com/google/common/collect/ImmutableRangeMap.java
index 72444245f..88ad7d889 100644
--- a/guava/src/com/google/common/collect/ImmutableRangeMap.java
+++ b/guava/src/com/google/common/collect/ImmutableRangeMap.java
@@ -372,6 +372,14 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
final ImmutableRangeMap<K, V> outer = this;
return new ImmutableRangeMap<K, V>(subRanges, values.subList(lowerIndex, upperIndex)) {
@@ -383,6 +391,14 @@ public class ImmutableRangeMap<K extends Comparable<?>, V> implements RangeMap<K
return ImmutableRangeMap.of();
}
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
diff --git a/guava/src/com/google/common/collect/ImmutableRangeSet.java b/guava/src/com/google/common/collect/ImmutableRangeSet.java
index afd421cd7..165b6e652 100644
--- a/guava/src/com/google/common/collect/ImmutableRangeSet.java
+++ b/guava/src/com/google/common/collect/ImmutableRangeSet.java
@@ -368,6 +368,14 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -487,6 +495,15 @@ public final class ImmutableRangeSet<C extends Comparable> extends AbstractRange
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
}
diff --git a/guava/src/com/google/common/collect/ImmutableSet.java b/guava/src/com/google/common/collect/ImmutableSet.java
index 6f2e1a15f..eeed833bf 100644
--- a/guava/src/com/google/common/collect/ImmutableSet.java
+++ b/guava/src/com/google/common/collect/ImmutableSet.java
@@ -22,6 +22,7 @@ import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.math.IntMath;
@@ -354,6 +355,15 @@ public abstract class ImmutableSet<E> extends ImmutableCollection<E> implements
ImmutableList<E> createAsList() {
return new RegularImmutableAsList<E>(this, toArray());
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
abstract static class Indexed<E> extends CachingAsList<E> {
@@ -395,8 +405,26 @@ public abstract class ImmutableSet<E> extends ImmutableCollection<E> implements
Indexed<E> delegateCollection() {
return Indexed.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
/*
diff --git a/guava/src/com/google/common/collect/ImmutableSetMultimap.java b/guava/src/com/google/common/collect/ImmutableSetMultimap.java
index 603580a50..b1f8438cd 100644
--- a/guava/src/com/google/common/collect/ImmutableSetMultimap.java
+++ b/guava/src/com/google/common/collect/ImmutableSetMultimap.java
@@ -553,6 +553,15 @@ public class ImmutableSetMultimap<K, V> extends ImmutableMultimap<K, V>
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private static <V> ImmutableSet<V> valueSet(
diff --git a/guava/src/com/google/common/collect/ImmutableSortedAsList.java b/guava/src/com/google/common/collect/ImmutableSortedAsList.java
index 30f19a02e..1736f2b8e 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedAsList.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedAsList.java
@@ -16,6 +16,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.Comparator;
import java.util.Spliterator;
import javax.annotation.CheckForNull;
@@ -93,4 +94,13 @@ final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E>
delegateList()::get,
comparator());
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/ImmutableSortedMap.java b/guava/src/com/google/common/collect/ImmutableSortedMap.java
index 55a10c291..ba0b91c95 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedMap.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedMap.java
@@ -23,6 +23,7 @@ import static com.google.common.collect.Maps.keyOrNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
@@ -844,6 +845,15 @@ public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V>
ImmutableCollection<Entry<K, V>> delegateCollection() {
return EntrySet.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
@@ -851,6 +861,15 @@ public final class ImmutableSortedMap<K, V> extends ImmutableMap<K, V>
ImmutableMap<K, V> map() {
return ImmutableSortedMap.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
return isEmpty() ? ImmutableSet.<Entry<K, V>>of() : new EntrySet();
}
diff --git a/guava/src/com/google/common/collect/ImmutableTable.java b/guava/src/com/google/common/collect/ImmutableTable.java
index 62cae079f..e1db67c93 100644
--- a/guava/src/com/google/common/collect/ImmutableTable.java
+++ b/guava/src/com/google/common/collect/ImmutableTable.java
@@ -445,9 +445,6 @@ public abstract class ImmutableTable<R, C, V> extends AbstractTable<R, C, V>
throw new UnsupportedOperationException();
}
- /** Creates the common serialized form for this table. */
- abstract SerializedForm createSerializedForm();
-
/**
* Serialized type for all ImmutableTable instances. It captures the logical contents and
* preserves iteration order of all views.
@@ -503,9 +500,9 @@ public abstract class ImmutableTable<R, C, V> extends AbstractTable<R, C, V>
private static final long serialVersionUID = 0;
}
- final Object writeReplace() {
- return createSerializedForm();
- }
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ abstract Object writeReplace();
@GwtIncompatible // serialization
@J2ktIncompatible
diff --git a/guava/src/com/google/common/collect/IndexedImmutableSet.java b/guava/src/com/google/common/collect/IndexedImmutableSet.java
index 20dfacbab..396ce6b0f 100644
--- a/guava/src/com/google/common/collect/IndexedImmutableSet.java
+++ b/guava/src/com/google/common/collect/IndexedImmutableSet.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.Spliterator;
import java.util.function.Consumer;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -76,6 +77,24 @@ abstract class IndexedImmutableSet<E> extends ImmutableSet.CachingAsList<E> {
ImmutableCollection<E> delegateCollection() {
return IndexedImmutableSet.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java b/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java
index f126fdea3..bf45138f7 100644
--- a/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java
+++ b/guava/src/com/google/common/collect/JdkBackedImmutableBiMap.java
@@ -18,6 +18,8 @@ package com.google.common.collect;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.concurrent.LazyInit;
import com.google.j2objc.annotations.RetainedWith;
@@ -102,6 +104,15 @@ final class JdkBackedImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
public int size() {
return entries.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -124,4 +135,13 @@ final class JdkBackedImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableMap.java b/guava/src/com/google/common/collect/JdkBackedImmutableMap.java
index 222c4deb8..0dd791923 100644
--- a/guava/src/com/google/common/collect/JdkBackedImmutableMap.java
+++ b/guava/src/com/google/common/collect/JdkBackedImmutableMap.java
@@ -21,6 +21,8 @@ import static com.google.common.collect.RegularImmutableMap.makeImmutable;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
@@ -130,4 +132,13 @@ final class JdkBackedImmutableMap<K, V> extends ImmutableMap<K, V> {
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java b/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java
index 41d95f045..8c116b351 100644
--- a/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java
+++ b/guava/src/com/google/common/collect/JdkBackedImmutableMultiset.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.primitives.Ints;
import com.google.errorprone.annotations.concurrent.LazyInit;
import java.util.Collection;
@@ -89,4 +91,13 @@ final class JdkBackedImmutableMultiset<E> extends ImmutableMultiset<E> {
public int size() {
return Ints.saturatedCast(size);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/JdkBackedImmutableSet.java b/guava/src/com/google/common/collect/JdkBackedImmutableSet.java
index c00167713..bee7076fa 100644
--- a/guava/src/com/google/common/collect/JdkBackedImmutableSet.java
+++ b/guava/src/com/google/common/collect/JdkBackedImmutableSet.java
@@ -15,6 +15,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.Set;
import javax.annotation.CheckForNull;
@@ -55,4 +57,13 @@ final class JdkBackedImmutableSet<E> extends IndexedImmutableSet<E> {
public int size() {
return delegateList.size();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/Lists.java b/guava/src/com/google/common/collect/Lists.java
index 0816b754a..a9c99e27a 100644
--- a/guava/src/com/google/common/collect/Lists.java
+++ b/guava/src/com/google/common/collect/Lists.java
@@ -780,6 +780,15 @@ public final class Lists {
public int size() {
return string.length();
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
private static final class CharSequenceAsList extends AbstractList<Character> {
diff --git a/guava/src/com/google/common/collect/RegularContiguousSet.java b/guava/src/com/google/common/collect/RegularContiguousSet.java
index 9c2e5a26f..8159d107b 100644
--- a/guava/src/com/google/common/collect/RegularContiguousSet.java
+++ b/guava/src/com/google/common/collect/RegularContiguousSet.java
@@ -143,6 +143,15 @@ final class RegularContiguousSet<C extends Comparable> extends ContiguousSet<C>
checkElementIndex(i, size());
return domain.offset(first(), i);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
} else {
return super.createAsList();
diff --git a/guava/src/com/google/common/collect/RegularImmutableAsList.java b/guava/src/com/google/common/collect/RegularImmutableAsList.java
index 0e3fe4ec8..bc4d8ae5d 100644
--- a/guava/src/com/google/common/collect/RegularImmutableAsList.java
+++ b/guava/src/com/google/common/collect/RegularImmutableAsList.java
@@ -18,6 +18,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.function.Consumer;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -91,4 +92,13 @@ class RegularImmutableAsList<E> extends ImmutableAsList<E> {
public E get(int index) {
return delegateList.get(index);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableBiMap.java b/guava/src/com/google/common/collect/RegularImmutableBiMap.java
index 333b80177..e97a86934 100644
--- a/guava/src/com/google/common/collect/RegularImmutableBiMap.java
+++ b/guava/src/com/google/common/collect/RegularImmutableBiMap.java
@@ -25,6 +25,7 @@ import static com.google.common.collect.RegularImmutableMap.checkNoConflictInKey
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMapEntry.NonTerminalImmutableBiMapEntry;
@@ -285,8 +286,26 @@ class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
ImmutableCollection<Entry<V, K>> delegateCollection() {
return InverseEntrySet.this;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
@Override
@@ -296,6 +315,7 @@ class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
@Override
@J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
Object writeReplace() {
return new InverseSerializedForm<>(RegularImmutableBiMap.this);
}
@@ -320,4 +340,13 @@ class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
private static final long serialVersionUID = 1;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableList.java b/guava/src/com/google/common/collect/RegularImmutableList.java
index 397147d70..e491617f4 100644
--- a/guava/src/com/google/common/collect/RegularImmutableList.java
+++ b/guava/src/com/google/common/collect/RegularImmutableList.java
@@ -17,6 +17,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import java.util.Spliterator;
import java.util.Spliterators;
@@ -91,4 +93,13 @@ class RegularImmutableList<E> extends ImmutableList<E> {
}
// TODO(lowasser): benchmark optimizations for equals() and see if they're worthwhile
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableMap.java b/guava/src/com/google/common/collect/RegularImmutableMap.java
index 42649109a..32aa2507a 100644
--- a/guava/src/com/google/common/collect/RegularImmutableMap.java
+++ b/guava/src/com/google/common/collect/RegularImmutableMap.java
@@ -346,6 +346,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
return map.size();
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@J2ktIncompatible
@@ -394,6 +403,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
return true;
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@J2ktIncompatible
@@ -414,6 +432,15 @@ final class RegularImmutableMap<K, V> extends ImmutableMap<K, V> {
}
}
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
+
// This class is never actually serialized directly, but we have to make the
// warning go away (and suppressing would suppress for all nested classes too)
@J2ktIncompatible // serialization
diff --git a/guava/src/com/google/common/collect/RegularImmutableMultiset.java b/guava/src/com/google/common/collect/RegularImmutableMultiset.java
index 026919e0d..8b50345b3 100644
--- a/guava/src/com/google/common/collect/RegularImmutableMultiset.java
+++ b/guava/src/com/google/common/collect/RegularImmutableMultiset.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Objects;
import com.google.common.collect.Multisets.ImmutableEntry;
@@ -194,4 +196,13 @@ class RegularImmutableMultiset<E> extends ImmutableMultiset<E> {
public int hashCode() {
return hashCode;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableSet.java b/guava/src/com/google/common/collect/RegularImmutableSet.java
index 211c89304..0db235d69 100644
--- a/guava/src/com/google/common/collect/RegularImmutableSet.java
+++ b/guava/src/com/google/common/collect/RegularImmutableSet.java
@@ -17,6 +17,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import java.util.Spliterator;
import java.util.Spliterators;
@@ -124,4 +126,13 @@ final class RegularImmutableSet<E> extends ImmutableSet.CachingAsList<E> {
boolean isHashCodeFast() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java b/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
index 4b7ba8742..258f7aa09 100644
--- a/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
+++ b/guava/src/com/google/common/collect/RegularImmutableSortedMultiset.java
@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkPositionIndexes;
import static com.google.common.collect.BoundType.CLOSED;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Ints;
import java.util.Comparator;
@@ -133,4 +134,12 @@ final class RegularImmutableSortedMultiset<E> extends ImmutableSortedMultiset<E>
boolean isPartialView() {
return offset > 0 || length < cumulativeCounts.length - 1;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
index 572e0acbf..970e85112 100644
--- a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
+++ b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -329,4 +330,13 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
? emptySet(reversedOrder)
: new RegularImmutableSortedSet<E>(elements.reverse(), reversedOrder);
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/RegularImmutableTable.java b/guava/src/com/google/common/collect/RegularImmutableTable.java
index 337f123b6..03def2cbc 100644
--- a/guava/src/com/google/common/collect/RegularImmutableTable.java
+++ b/guava/src/com/google/common/collect/RegularImmutableTable.java
@@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.j2objc.annotations.WeakOuter;
import java.util.Collections;
import java.util.Comparator;
@@ -69,6 +71,15 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
abstract V getValue(int iterationIndex);
@@ -94,6 +105,15 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
static <R, C, V> RegularImmutableTable<R, C, V> forCells(
@@ -181,4 +201,10 @@ abstract class RegularImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
newValue,
existingValue);
}
+
+ // redeclare to satisfy our test for b/310253115
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ abstract Object writeReplace();
}
diff --git a/guava/src/com/google/common/collect/Sets.java b/guava/src/com/google/common/collect/Sets.java
index 86663d58a..c38181001 100644
--- a/guava/src/com/google/common/collect/Sets.java
+++ b/guava/src/com/google/common/collect/Sets.java
@@ -1432,6 +1432,15 @@ public final class Sets {
boolean isPartialView() {
return true;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
};
return new CartesianSet<E>(axes, new CartesianList<E>(listAxes));
}
diff --git a/guava/src/com/google/common/collect/SingletonImmutableBiMap.java b/guava/src/com/google/common/collect/SingletonImmutableBiMap.java
index c5fb2b298..c2f4ae137 100644
--- a/guava/src/com/google/common/collect/SingletonImmutableBiMap.java
+++ b/guava/src/com/google/common/collect/SingletonImmutableBiMap.java
@@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkEntryNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.concurrent.LazyInit;
import com.google.j2objc.annotations.RetainedWith;
import java.util.function.BiConsumer;
@@ -110,4 +112,13 @@ final class SingletonImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
}
}
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/SingletonImmutableList.java b/guava/src/com/google/common/collect/SingletonImmutableList.java
index a7ac8b30e..ba1b1a713 100644
--- a/guava/src/com/google/common/collect/SingletonImmutableList.java
+++ b/guava/src/com/google/common/collect/SingletonImmutableList.java
@@ -19,6 +19,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Preconditions;
import java.util.Collections;
import java.util.Spliterator;
@@ -75,4 +77,13 @@ final class SingletonImmutableList<E> extends ImmutableList<E> {
boolean isPartialView() {
return false;
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/SingletonImmutableSet.java b/guava/src/com/google/common/collect/SingletonImmutableSet.java
index 088cb802f..15db1c5e5 100644
--- a/guava/src/com/google/common/collect/SingletonImmutableSet.java
+++ b/guava/src/com/google/common/collect/SingletonImmutableSet.java
@@ -17,6 +17,8 @@
package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.common.base.Preconditions;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -80,4 +82,13 @@ final class SingletonImmutableSet<E> extends ImmutableSet<E> {
public String toString() {
return '[' + element.toString() + ']';
}
+
+ // redeclare to help optimizers with b/310253115
+ @SuppressWarnings("RedundantOverride")
+ @Override
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
+ return super.writeReplace();
+ }
}
diff --git a/guava/src/com/google/common/collect/SingletonImmutableTable.java b/guava/src/com/google/common/collect/SingletonImmutableTable.java
index cfaeadb41..6f839ceb4 100644
--- a/guava/src/com/google/common/collect/SingletonImmutableTable.java
+++ b/guava/src/com/google/common/collect/SingletonImmutableTable.java
@@ -19,6 +19,8 @@ package com.google.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import java.util.Map;
/**
@@ -77,7 +79,9 @@ class SingletonImmutableTable<R, C, V> extends ImmutableTable<R, C, V> {
}
@Override
- SerializedForm createSerializedForm() {
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
return SerializedForm.create(this, new int[] {0}, new int[] {0});
}
}
diff --git a/guava/src/com/google/common/collect/SparseImmutableTable.java b/guava/src/com/google/common/collect/SparseImmutableTable.java
index 44881fde7..f7222b120 100644
--- a/guava/src/com/google/common/collect/SparseImmutableTable.java
+++ b/guava/src/com/google/common/collect/SparseImmutableTable.java
@@ -17,6 +17,8 @@ package com.google.common.collect;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtCompatible;
+import com.google.common.annotations.GwtIncompatible;
+import com.google.common.annotations.J2ktIncompatible;
import com.google.errorprone.annotations.Immutable;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -130,7 +132,9 @@ final class SparseImmutableTable<R, C, V> extends RegularImmutableTable<R, C, V>
}
@Override
- SerializedForm createSerializedForm() {
+ @J2ktIncompatible // serialization
+ @GwtIncompatible // serialization
+ Object writeReplace() {
Map<C, Integer> columnKeyToIndex = Maps.indexMap(columnKeySet());
int[] cellColumnIndices = new int[cellSet().size()];
int i = 0;