Skip to content

Commit

Permalink
Bring back previously deleted SerializedForms so that old data can st…
Browse files Browse the repository at this point in the history
…ill be read.

RELNOTES=`collect`: Data that was previously serialized, and that originated from ImmutableMap.keySet() or .values(), is now deserializable again.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=326086350
  • Loading branch information
antiufo authored and cgdecker committed Aug 12, 2020
1 parent b6b4dc4 commit 6193884
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
19 changes: 19 additions & 0 deletions guava/src/com/google/common/collect/ImmutableMapKeySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.io.Serializable;
import java.util.Spliterator;
import java.util.function.Consumer;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -72,4 +74,21 @@ public void forEach(Consumer<? super K> action) {
boolean isPartialView() {
return true;
}

// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@SuppressWarnings("unused")
private static class KeySetSerializedForm<K> implements Serializable {
final ImmutableMap<K, ?> map;

KeySetSerializedForm(ImmutableMap<K, ?> map) {
this.map = map;
}

Object readResolve() {
return map.keySet();
}

private static final long serialVersionUID = 0;
}
}
18 changes: 18 additions & 0 deletions guava/src/com/google/common/collect/ImmutableMapValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.io.Serializable;
import java.util.Map.Entry;
import java.util.Spliterator;
import java.util.function.Consumer;
Expand Down Expand Up @@ -98,4 +99,21 @@ public void forEach(Consumer<? super V> action) {
checkNotNull(action);
map.forEach((k, v) -> action.accept(v));
}

// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@SuppressWarnings("unused")
private static class SerializedForm<V> implements Serializable {
final ImmutableMap<?, V> map;

SerializedForm(ImmutableMap<?, V> map) {
this.map = map;
}

Object readResolve() {
return map.values();
}

private static final long serialVersionUID = 0;
}
}
36 changes: 36 additions & 0 deletions guava/src/com/google/common/collect/RegularImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import static com.google.common.collect.ImmutableMapEntry.createEntryArray;

import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMapEntry.NonTerminalImmutableMapEntry;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.Serializable;
import java.util.function.BiConsumer;
import org.checkerframework.checker.nullness.qual.Nullable;

Expand Down Expand Up @@ -231,6 +233,23 @@ boolean isPartialView() {
public int size() {
return map.size();
}

// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@SuppressWarnings("unused")
private static class SerializedForm<K> implements Serializable {
final ImmutableMap<K, ?> map;

SerializedForm(ImmutableMap<K, ?> map) {
this.map = map;
}

Object readResolve() {
return map.keySet();
}

private static final long serialVersionUID = 0;
}
}

@Override
Expand Down Expand Up @@ -260,6 +279,23 @@ public int size() {
boolean isPartialView() {
return true;
}

// No longer used for new writes, but kept so that old data can still be read.
@GwtIncompatible // serialization
@SuppressWarnings("unused")
private static class SerializedForm<V> implements Serializable {
final ImmutableMap<?, V> map;

SerializedForm(ImmutableMap<?, V> map) {
this.map = map;
}

Object readResolve() {
return map.values();
}

private static final long serialVersionUID = 0;
}
}

// This class is never actually serialized directly, but we have to make the
Expand Down

0 comments on commit 6193884

Please sign in to comment.