Skip to content

Commit e62d6a0

Browse files
eamonnmcmanusGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedMay 25, 2022
Add exception-throwing readObject to classes using the serial-proxy pattern.
See _Effective Java_, 3rd edition, Item 90. RELNOTES=Classes with "serial proxies" acquire exception-throwing `readObject` methods, in accordance with best practice. PiperOrigin-RevId: 451001736
1 parent 76260d9 commit e62d6a0

Some content is hidden

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

46 files changed

+312
-0
lines changed
 

‎android/guava/src/com/google/common/cache/LocalCache.java

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.google.j2objc.annotations.RetainedWith;
5555
import com.google.j2objc.annotations.Weak;
5656
import java.io.IOException;
57+
import java.io.InvalidObjectException;
5758
import java.io.ObjectInputStream;
5859
import java.io.Serializable;
5960
import java.lang.ref.Reference;
@@ -4748,6 +4749,10 @@ public void cleanUp() {
47484749
Object writeReplace() {
47494750
return new ManualSerializationProxy<>(localCache);
47504751
}
4752+
4753+
private void readObject(ObjectInputStream in) throws InvalidObjectException {
4754+
throw new InvalidObjectException("Use ManualSerializationProxy");
4755+
}
47514756
}
47524757

47534758
static class LocalLoadingCache<K, V> extends LocalManualCache<K, V>
@@ -4797,5 +4802,9 @@ public final V apply(K key) {
47974802
Object writeReplace() {
47984803
return new LoadingSerializationProxy<>(localCache);
47994804
}
4805+
4806+
private void readObject(ObjectInputStream in) throws InvalidObjectException {
4807+
throw new InvalidObjectException("Use LoadingSerializationProxy");
4808+
}
48004809
}
48014810
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import com.google.common.annotations.GwtCompatible;
1717
import com.google.common.annotations.GwtIncompatible;
18+
import java.io.InvalidObjectException;
19+
import java.io.ObjectInputStream;
1820
import java.io.Serializable;
1921
import java.util.NoSuchElementException;
2022
import java.util.Set;
@@ -162,6 +164,11 @@ Object writeReplace() {
162164
return new SerializedForm<>(domain);
163165
}
164166

167+
@GwtIncompatible // serialization
168+
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
169+
throw new InvalidObjectException("Use SerializedForm");
170+
}
171+
165172
@GwtIncompatible // NavigableSet
166173
@Override
167174
ImmutableSortedSet<C> createDescendingSet() {

0 commit comments

Comments
 (0)