Skip to content

Commit 412c1bf

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Continue standardizing annotations on serialization-related members.
Compare cl/725785821 and cl/745110143. (I suppose we could imagine a future in which GWT, J2CL, and J2KT all _automatically_ strip members annotated with `@Serial`. We'd still need `@GwtIncompatible` and `@J2ktIncompatible` for "helpers" (i.e., classes, fields, and methods that aren't directly called by the Java serialization system), but we could at least omit those annotations from the `@Serial` members themselves.) RELNOTES=n/a PiperOrigin-RevId: 747924219
1 parent 0232f38 commit 412c1bf

File tree

60 files changed

+233
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+233
-233
lines changed

android/guava-tests/test/com/google/common/collect/ArrayTableTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ public void testNulls() {
467467
new NullPointerTester().testAllPublicInstanceMethods(create());
468468
}
469469

470+
@GwtIncompatible
470471
@J2ktIncompatible
471-
@GwtIncompatible // serialize
472-
public void testSerializable() {
472+
public void testSerializable() {
473473
SerializableTester.reserializeAndAssert(create());
474474
}
475475
}

android/guava-tests/test/com/google/common/collect/EnumBiMapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ public void testEntrySet() {
291291
assertEquals(3, uniqueEntries.size());
292292
}
293293

294+
@GwtIncompatible
294295
@J2ktIncompatible
295-
@GwtIncompatible // serialization
296-
public void testSerializable() {
296+
public void testSerializable() {
297297
SerializableTester.reserializeAndAssert(
298298
EnumBiMap.create(ImmutableMap.of(Currency.DOLLAR, Country.CANADA)));
299299
}

android/guava-tests/test/com/google/common/collect/EnumHashBiMapTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ public void testEntrySet() {
225225
assertEquals(3, uniqueEntries.size());
226226
}
227227

228+
@GwtIncompatible
228229
@J2ktIncompatible
229-
@GwtIncompatible // serialize
230-
public void testSerializable() {
230+
public void testSerializable() {
231231
SerializableTester.reserializeAndAssert(EnumHashBiMap.create(Currency.class));
232232
}
233233

android/guava-tests/test/com/google/common/collect/MultimapBuilderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ SortedSetMultimapBuilder<K, Comparable<?>> rawtypeToWildcard(
9393
return (SortedSetMultimapBuilder) setMultimapBuilder;
9494
}
9595

96+
@GwtIncompatible
9697
@J2ktIncompatible
97-
@GwtIncompatible // serialization
98-
public void testSerialization() throws Exception {
98+
public void testSerialization() throws Exception {
9999
for (MultimapBuilderWithKeys<?> builderWithKeys :
100100
ImmutableList.of(
101101
MultimapBuilder.hashKeys(),
@@ -118,17 +118,17 @@ public void testSerialization() throws Exception {
118118
}
119119
}
120120

121+
@GwtIncompatible
121122
@J2ktIncompatible
122-
@GwtIncompatible // serialization
123-
private static void reserializeAndAssert(Object object) throws Exception {
123+
private static void reserializeAndAssert(Object object) throws Exception {
124124
Object copy = reserialize(object);
125125
assertEquals(object, copy);
126126
assertEquals(object.getClass(), copy.getClass());
127127
}
128128

129+
@GwtIncompatible
129130
@J2ktIncompatible
130-
@GwtIncompatible // serialization
131-
private static Object reserialize(Object object) throws Exception {
131+
private static Object reserialize(Object object) throws Exception {
132132
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
133133
new ObjectOutputStream(bytes).writeObject(object);
134134
return new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject();

android/guava-tests/test/com/google/common/collect/SetsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ public void testImmutableEnumSet_fromIterable() {
316316
assertThat(two).containsExactly(SomeEnum.B, SomeEnum.D).inOrder();
317317
}
318318

319+
@GwtIncompatible
319320
@J2ktIncompatible
320-
@GwtIncompatible // java serialization not supported in GWT.
321-
public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception {
321+
public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception {
322322
ImmutableSet<SomeEnum> original = Sets.immutableEnumSet(SomeEnum.A, SomeEnum.B);
323323
int handleOffset = 6;
324324
byte[] serializedForm = serializeWithBackReference(original, handleOffset);
@@ -332,9 +332,9 @@ public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exce
332332
assertTrue(deserialized.contains(SomeEnum.A));
333333
}
334334

335+
@GwtIncompatible
335336
@J2ktIncompatible
336-
@GwtIncompatible // java serialization not supported in GWT.
337-
private static byte[] serializeWithBackReference(Object original, int handleOffset)
337+
private static byte[] serializeWithBackReference(Object original, int handleOffset)
338338
throws IOException {
339339
ByteArrayOutputStream bos = new ByteArrayOutputStream();
340340
ObjectOutputStream out = new ObjectOutputStream(bos);

android/guava-tests/test/com/google/common/primitives/UnsignedIntegerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ public void testIntValue() {
274274
}
275275
}
276276

277+
@GwtIncompatible
277278
@J2ktIncompatible
278-
@GwtIncompatible // serialization
279-
public void testSerialization() {
279+
public void testSerialization() {
280280
for (int a : TEST_INTS) {
281281
SerializableTester.reserializeAndAssert(UnsignedInteger.fromIntBits(a));
282282
}

android/guava-tests/test/com/google/common/primitives/UnsignedLongTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ public void testIntValue() {
283283
}
284284
}
285285

286+
@GwtIncompatible
286287
@J2ktIncompatible
287-
@GwtIncompatible // serialization
288-
public void testSerialization() {
288+
public void testSerialization() {
289289
for (long a : TEST_LONGS) {
290290
SerializableTester.reserializeAndAssert(UnsignedLong.fromLongBits(a));
291291
}

android/guava/src/com/google/common/base/Suppliers.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public String toString() {
159159
+ ")";
160160
}
161161

162-
@GwtIncompatible // serialization
163-
@J2ktIncompatible // serialization
164-
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
162+
@GwtIncompatible
163+
@J2ktIncompatible
164+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
165165
in.defaultReadObject();
166166
lock = new Object();
167167
}
@@ -332,9 +332,9 @@ public String toString() {
332332
return "Suppliers.memoizeWithExpiration(" + delegate + ", " + durationNanos + ", NANOS)";
333333
}
334334

335-
@GwtIncompatible // serialization
336-
@J2ktIncompatible // serialization
337-
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
335+
@GwtIncompatible
336+
@J2ktIncompatible
337+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
338338
in.defaultReadObject();
339339
lock = new Object();
340340
}

android/guava/src/com/google/common/collect/AbstractBiMap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,16 @@ V checkValue(@ParametricNullness V value) {
462462
/**
463463
* @serialData the forward bimap
464464
*/
465-
@GwtIncompatible // java.io.ObjectOutputStream
465+
@GwtIncompatible
466466
@J2ktIncompatible
467-
private void writeObject(ObjectOutputStream stream) throws IOException {
467+
private void writeObject(ObjectOutputStream stream) throws IOException {
468468
stream.defaultWriteObject();
469469
stream.writeObject(inverse());
470470
}
471471

472-
@GwtIncompatible // java.io.ObjectInputStream
472+
@GwtIncompatible
473473
@J2ktIncompatible
474-
@SuppressWarnings("unchecked") // reading data stored by writeObject
474+
@SuppressWarnings("unchecked") // reading data stored by writeObject
475475
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
476476
stream.defaultReadObject();
477477
setInverse((AbstractBiMap<V, K>) requireNonNull(stream.readObject()));

android/guava/src/com/google/common/collect/AbstractMapBasedMultiset.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,16 @@ public final int size() {
253253
* @serialData the number of distinct elements, the first element, its count, the second element,
254254
* its count, and so on
255255
*/
256-
@GwtIncompatible // java.io.ObjectOutputStream
256+
@GwtIncompatible
257257
@J2ktIncompatible
258-
private void writeObject(ObjectOutputStream stream) throws IOException {
258+
private void writeObject(ObjectOutputStream stream) throws IOException {
259259
stream.defaultWriteObject();
260260
Serialization.writeMultiset(this, stream);
261261
}
262262

263-
@GwtIncompatible // java.io.ObjectInputStream
263+
@GwtIncompatible
264264
@J2ktIncompatible
265-
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
265+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
266266
stream.defaultReadObject();
267267
int distinctElements = Serialization.readCount(stream);
268268
backingMap = newBackingMap(ObjectCountHashMap.DEFAULT_SIZE);

android/guava/src/com/google/common/collect/ArrayListMultimap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ public void trimToSize() {
157157
* @serialData expectedValuesPerKey, number of distinct keys, and then for each distinct key: the
158158
* key, number of values for that key, and the key's values
159159
*/
160-
@GwtIncompatible // java.io.ObjectOutputStream
160+
@GwtIncompatible
161161
@J2ktIncompatible
162-
private void writeObject(ObjectOutputStream stream) throws IOException {
162+
private void writeObject(ObjectOutputStream stream) throws IOException {
163163
stream.defaultWriteObject();
164164
Serialization.writeMultimap(this, stream);
165165
}
166166

167-
@GwtIncompatible // java.io.ObjectOutputStream
167+
@GwtIncompatible
168168
@J2ktIncompatible
169-
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
169+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
170170
stream.defaultReadObject();
171171
expectedValuesPerKey = DEFAULT_VALUES_PER_KEY;
172172
int distinctKeys = Serialization.readCount(stream);

android/guava/src/com/google/common/collect/EmptyContiguousSet.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public int hashCode() {
145145
return 0;
146146
}
147147

148-
@GwtIncompatible // serialization
148+
@GwtIncompatible
149149
@J2ktIncompatible
150150
private static final class SerializedForm<C extends Comparable> implements Serializable {
151151
private final DiscreteDomain<C> domain;
@@ -161,16 +161,16 @@ private Object readResolve() {
161161
@GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0;
162162
}
163163

164-
@GwtIncompatible // serialization
164+
@GwtIncompatible
165165
@J2ktIncompatible
166-
@Override
166+
@Override
167167
Object writeReplace() {
168168
return new SerializedForm<>(domain);
169169
}
170170

171-
@GwtIncompatible // serialization
171+
@GwtIncompatible
172172
@J2ktIncompatible
173-
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
173+
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
174174
throw new InvalidObjectException("Use SerializedForm");
175175
}
176176

android/guava/src/com/google/common/collect/HashBiMap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,16 +1129,16 @@ public K setValue(@ParametricNullness K key) {
11291129
/**
11301130
* @serialData the number of entries, first key, first value, second key, second value, and so on.
11311131
*/
1132-
@GwtIncompatible // java.io.ObjectOutputStream
1132+
@GwtIncompatible
11331133
@J2ktIncompatible
1134-
private void writeObject(ObjectOutputStream stream) throws IOException {
1134+
private void writeObject(ObjectOutputStream stream) throws IOException {
11351135
stream.defaultWriteObject();
11361136
Serialization.writeMap(this, stream);
11371137
}
11381138

1139-
@GwtIncompatible // java.io.ObjectInputStream
1139+
@GwtIncompatible
11401140
@J2ktIncompatible
1141-
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
1141+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
11421142
stream.defaultReadObject();
11431143
int size = Serialization.readCount(stream);
11441144
init(16); // resist hostile attempts to allocate gratuitous heap

android/guava/src/com/google/common/collect/HashMultimap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ Set<V> createCollection() {
133133
* @serialData expectedValuesPerKey, number of distinct keys, and then for each distinct key: the
134134
* key, number of values for that key, and the key's values
135135
*/
136-
@GwtIncompatible // java.io.ObjectOutputStream
136+
@GwtIncompatible
137137
@J2ktIncompatible
138-
private void writeObject(ObjectOutputStream stream) throws IOException {
138+
private void writeObject(ObjectOutputStream stream) throws IOException {
139139
stream.defaultWriteObject();
140140
Serialization.writeMultimap(this, stream);
141141
}
142142

143-
@GwtIncompatible // java.io.ObjectInputStream
143+
@GwtIncompatible
144144
@J2ktIncompatible
145-
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
145+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
146146
stream.defaultReadObject();
147147
expectedValuesPerKey = DEFAULT_VALUES_PER_KEY;
148148
int distinctKeys = Serialization.readCount(stream);

android/guava/src/com/google/common/collect/ImmutableAsList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ boolean isPartialView() {
5959
}
6060

6161
/** Serialized form that leads to the same performance as the original list. */
62-
@GwtIncompatible // serialization
62+
@GwtIncompatible
6363
@J2ktIncompatible
6464
static class SerializedForm implements Serializable {
6565
final ImmutableCollection<?> collection;
@@ -75,15 +75,15 @@ Object readResolve() {
7575
@GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 0;
7676
}
7777

78-
@GwtIncompatible // serialization
78+
@GwtIncompatible
7979
@J2ktIncompatible
80-
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
80+
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
8181
throw new InvalidObjectException("Use SerializedForm");
8282
}
8383

84-
@GwtIncompatible // serialization
84+
@GwtIncompatible
8585
@J2ktIncompatible
86-
@Override
86+
@Override
8787
Object writeReplace() {
8888
return new SerializedForm(delegateCollection());
8989
}

android/guava/src/com/google/common/collect/ImmutableListMultimap.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,16 +511,16 @@ public final ImmutableList<V> replaceValues(K key, Iterable<? extends V> values)
511511
* @serialData number of distinct keys, and then for each distinct key: the key, the number of
512512
* values for that key, and the key's values
513513
*/
514-
@GwtIncompatible // java.io.ObjectOutputStream
514+
@GwtIncompatible
515515
@J2ktIncompatible
516-
private void writeObject(ObjectOutputStream stream) throws IOException {
516+
private void writeObject(ObjectOutputStream stream) throws IOException {
517517
stream.defaultWriteObject();
518518
Serialization.writeMultimap(this, stream);
519519
}
520520

521-
@GwtIncompatible // java.io.ObjectInputStream
521+
@GwtIncompatible
522522
@J2ktIncompatible
523-
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
523+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
524524
stream.defaultReadObject();
525525
int keyCount = stream.readInt();
526526
if (keyCount < 0) {

android/guava/src/com/google/common/collect/ImmutableMapEntrySet.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,20 @@ public int hashCode() {
112112
return map().hashCode();
113113
}
114114

115-
@GwtIncompatible // serialization
115+
@GwtIncompatible
116116
@J2ktIncompatible
117-
@Override
117+
@Override
118118
Object writeReplace() {
119119
return new EntrySetSerializedForm<>(map());
120120
}
121121

122-
@GwtIncompatible // serialization
122+
@GwtIncompatible
123123
@J2ktIncompatible
124-
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
124+
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
125125
throw new InvalidObjectException("Use EntrySetSerializedForm");
126126
}
127127

128-
@GwtIncompatible // serialization
128+
@GwtIncompatible
129129
@J2ktIncompatible
130130
private static class EntrySetSerializedForm<K, V> implements Serializable {
131131
final ImmutableMap<K, V> map;

android/guava/src/com/google/common/collect/ImmutableMapKeySet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Object writeReplace() {
6868
return new KeySetSerializedForm<K>(map);
6969
}
7070

71-
@GwtIncompatible // serialization
71+
@GwtIncompatible
7272
@J2ktIncompatible
7373
private static class KeySetSerializedForm<K> implements Serializable {
7474
final ImmutableMap<K, ?> map;

android/guava/src/com/google/common/collect/ImmutableMultimap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public static <K, V> ImmutableMultimap<K, V> copyOf(
411411
// These constants allow the deserialization code to set final fields. This
412412
// holder class makes sure they are not initialized unless an instance is
413413
// deserialized.
414-
@GwtIncompatible // java serialization is not supported
414+
@GwtIncompatible
415415
@J2ktIncompatible
416416
static class FieldSettersHolder {
417417
static final Serialization.FieldSetter<? super ImmutableMultimap<?, ?>> MAP_FIELD_SETTER =

0 commit comments

Comments
 (0)