8231202: Suppress warnings on non-serializable non-transient instance fields in serializable classes
authordarcy
Wed, 09 Oct 2019 10:17:50 -0700
changeset 58520 e036ee8bae56
parent 58519 6e017b301287
child 58521 55d2e10ea134
8231202: Suppress warnings on non-serializable non-transient instance fields in serializable classes Reviewed-by: rriggs, chegar
src/java.base/share/classes/java/lang/Throwable.java
src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
src/java.base/share/classes/java/lang/reflect/Proxy.java
src/java.base/share/classes/java/time/Clock.java
src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java
src/java.base/share/classes/java/util/AbstractMap.java
src/java.base/share/classes/java/util/ArrayPrefixHelpers.java
src/java.base/share/classes/java/util/Arrays.java
src/java.base/share/classes/java/util/ArraysParallelSortHelpers.java
src/java.base/share/classes/java/util/Collections.java
src/java.base/share/classes/java/util/Comparators.java
src/java.base/share/classes/java/util/PriorityQueue.java
src/java.base/share/classes/java/util/TreeMap.java
src/java.base/share/classes/java/util/Vector.java
src/java.base/share/classes/java/util/jar/JarVerifier.java
src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java
src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java
src/java.base/share/classes/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java
--- a/src/java.base/share/classes/java/lang/Throwable.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/lang/Throwable.java	Wed Oct 09 10:17:50 2019 -0700
@@ -230,6 +230,7 @@
      * @serial
      * @since 1.7
      */
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     private List<Throwable> suppressedExceptions = SUPPRESSED_SENTINEL;
 
     /** Message for trying to suppress a null exception. */
--- a/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java	Wed Oct 09 10:17:50 2019 -0700
@@ -76,6 +76,7 @@
     private final String implMethodSignature;
     private final int implMethodKind;
     private final String instantiatedMethodType;
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     private final Object[] capturedArgs;
 
     /**
--- a/src/java.base/share/classes/java/lang/reflect/Proxy.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/lang/reflect/Proxy.java	Wed Oct 09 10:17:50 2019 -0700
@@ -308,6 +308,7 @@
      * the invocation handler for this proxy instance.
      * @serial
      */
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     protected InvocationHandler h;
 
     /**
--- a/src/java.base/share/classes/java/time/Clock.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/time/Clock.java	Wed Oct 09 10:17:50 2019 -0700
@@ -641,6 +641,7 @@
     static final class OffsetClock extends Clock implements Serializable {
         @java.io.Serial
         private static final long serialVersionUID = 2007484719125426256L;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         private final Clock baseClock;
         private final Duration offset;
 
@@ -692,6 +693,7 @@
     static final class TickClock extends Clock implements Serializable {
         @java.io.Serial
         private static final long serialVersionUID = 6504659149906368850L;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         private final Clock baseClock;
         private final long tickNanos;
 
--- a/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/time/chrono/ChronoPeriodImpl.java	Wed Oct 09 10:17:50 2019 -0700
@@ -109,6 +109,7 @@
     /**
      * The chronology.
      */
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     private final Chronology chrono;
     /**
      * The number of years.
--- a/src/java.base/share/classes/java/util/AbstractMap.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/AbstractMap.java	Wed Oct 09 10:17:50 2019 -0700
@@ -607,7 +607,9 @@
         @java.io.Serial
         private static final long serialVersionUID = -8499721149061103585L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final K key;
+        @SuppressWarnings("serial") // Conditionally serializable
         private V value;
 
         /**
@@ -738,7 +740,9 @@
         @java.io.Serial
         private static final long serialVersionUID = 7138329143949025153L;
 
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         private final K key;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         private final V value;
 
         /**
--- a/src/java.base/share/classes/java/util/ArrayPrefixHelpers.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/ArrayPrefixHelpers.java	Wed Oct 09 10:17:50 2019 -0700
@@ -103,10 +103,15 @@
     static final int MIN_PARTITION = 16;
 
     static final class CumulateTask<T> extends CountedCompleter<Void> {
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         final T[] array;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         final BinaryOperator<T> function;
         CumulateTask<T> left, right;
-        T in, out;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
+        T in;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
+        T out;
         final int lo, hi, origin, fence, threshold;
 
         /** Root task constructor */
@@ -257,6 +262,7 @@
 
     static final class LongCumulateTask extends CountedCompleter<Void> {
         final long[] array;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         final LongBinaryOperator function;
         LongCumulateTask left, right;
         long in, out;
@@ -408,6 +414,7 @@
 
     static final class DoubleCumulateTask extends CountedCompleter<Void> {
         final double[] array;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         final DoubleBinaryOperator function;
         DoubleCumulateTask left, right;
         double in, out;
@@ -559,6 +566,7 @@
 
     static final class IntCumulateTask extends CountedCompleter<Void> {
         final int[] array;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         final IntBinaryOperator function;
         IntCumulateTask left, right;
         int in, out;
--- a/src/java.base/share/classes/java/util/Arrays.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/Arrays.java	Wed Oct 09 10:17:50 2019 -0700
@@ -4339,6 +4339,7 @@
     {
         @java.io.Serial
         private static final long serialVersionUID = -2764017481108945198L;
+        @SuppressWarnings("serial") // Conditionally serializable
         private final E[] a;
 
         ArrayList(E[] array) {
--- a/src/java.base/share/classes/java/util/ArraysParallelSortHelpers.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/ArraysParallelSortHelpers.java	Wed Oct 09 10:17:50 2019 -0700
@@ -115,8 +115,12 @@
         static final class Sorter<T> extends CountedCompleter<Void> {
             @java.io.Serial
             static final long serialVersionUID = 2446542900576103244L;
-            final T[] a, w;
+            @SuppressWarnings("serial") // Not statically typed as Serializable
+            final T[] a;
+            @SuppressWarnings("serial") // Not statically typed as Serializable
+            final T[] w;
             final int base, size, wbase, gran;
+            @SuppressWarnings("serial") // Not statically typed as Serializable
             Comparator<? super T> comparator;
             Sorter(CountedCompleter<?> par, T[] a, T[] w, int base, int size,
                    int wbase, int gran,
@@ -153,8 +157,13 @@
         static final class Merger<T> extends CountedCompleter<Void> {
             @java.io.Serial
             static final long serialVersionUID = 2446542900576103244L;
-            final T[] a, w; // main and workspace arrays
+             // main and workspace arrays
+            @SuppressWarnings("serial") // Not statically typed as Serializable
+            final T[] a;
+            @SuppressWarnings("serial") // Not statically typed as Serializable
+            final T[] w;
             final int lbase, lsize, rbase, rsize, wbase, gran;
+            @SuppressWarnings("serial") // Not statically typed as Serializable
             Comparator<? super T> comparator;
             Merger(CountedCompleter<?> par, T[] a, T[] w,
                    int lbase, int lsize, int rbase,
--- a/src/java.base/share/classes/java/util/Collections.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/Collections.java	Wed Oct 09 10:17:50 2019 -0700
@@ -1024,6 +1024,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 1820017752578914078L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         final Collection<? extends E> c;
 
         UnmodifiableCollection(Collection<? extends E> c) {
@@ -1164,6 +1165,7 @@
                              implements SortedSet<E>, Serializable {
         @java.io.Serial
         private static final long serialVersionUID = -4929149591599911165L;
+        @SuppressWarnings("serial") // Conditionally serializable
         private final SortedSet<E> ss;
 
         UnmodifiableSortedSet(SortedSet<E> s) {super(s); ss = s;}
@@ -1244,6 +1246,7 @@
         /**
          * The instance we are protecting.
          */
+        @SuppressWarnings("serial") // Conditionally serializable
         private final NavigableSet<E> ns;
 
         UnmodifiableNavigableSet(NavigableSet<E> s)         {super(s); ns = s;}
@@ -1304,6 +1307,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -283967356065247728L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         final List<? extends E> list;
 
         UnmodifiableList(List<? extends E> list) {
@@ -1450,6 +1454,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -1034234728574286014L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final Map<? extends K, ? extends V> m;
 
         UnmodifiableMap(Map<? extends K, ? extends V> m) {
@@ -1809,6 +1814,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -8806743815996713206L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final SortedMap<K, ? extends V> sm;
 
         UnmodifiableSortedMap(SortedMap<K, ? extends V> m) {super(m); sm = m; }
@@ -1886,6 +1892,7 @@
         /**
          * The instance we wrap and protect.
          */
+        @SuppressWarnings("serial") // Conditionally serializable
         private final NavigableMap<K, ? extends V> nm;
 
         UnmodifiableNavigableMap(NavigableMap<K, ? extends V> m)
@@ -2017,7 +2024,9 @@
         @java.io.Serial
         private static final long serialVersionUID = 3053995032091335093L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         final Collection<E> c;  // Backing Collection
+        @SuppressWarnings("serial") // Conditionally serializable
         final Object mutex;     // Object on which to synchronize
 
         SynchronizedCollection(Collection<E> c) {
@@ -2219,6 +2228,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 8695801310862127406L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final SortedSet<E> ss;
 
         SynchronizedSortedSet(SortedSet<E> s) {
@@ -2314,6 +2324,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -5505529816273629798L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final NavigableSet<E> ns;
 
         SynchronizedNavigableSet(NavigableSet<E> s) {
@@ -2424,6 +2435,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -7754090372962971524L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         final List<E> list;
 
         SynchronizedList(List<E> list) {
@@ -2591,7 +2603,9 @@
         @java.io.Serial
         private static final long serialVersionUID = 1978198479659022715L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final Map<K,V> m;     // Backing Map
+        @SuppressWarnings("serial") // Conditionally serializable
         final Object      mutex;        // Object on which to synchronize
 
         SynchronizedMap(Map<K,V> m) {
@@ -2788,6 +2802,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -8798146769416483793L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final SortedMap<K,V> sm;
 
         SynchronizedSortedMap(SortedMap<K,V> m) {
@@ -2891,6 +2906,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 699392247599746807L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final NavigableMap<K,V> nm;
 
         SynchronizedNavigableMap(NavigableMap<K,V> m) {
@@ -3070,7 +3086,9 @@
         @java.io.Serial
         private static final long serialVersionUID = 1578914078182001775L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         final Collection<E> c;
+        @SuppressWarnings("serial") // Conditionally serializable
         final Class<E> type;
 
         @SuppressWarnings("unchecked")
@@ -3126,6 +3144,7 @@
 
         public boolean add(E e)          { return c.add(typeCheck(e)); }
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private E[] zeroLengthElementArray; // Lazily initialized
 
         private E[] zeroLengthElementArray() {
@@ -3219,6 +3238,7 @@
     {
         @java.io.Serial
         private static final long serialVersionUID = 1433151992604707767L;
+        @SuppressWarnings("serial") // Conditionally serializable
         final Queue<E> queue;
 
         CheckedQueue(Queue<E> queue, Class<E> elementType) {
@@ -3323,6 +3343,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 1599911165492914959L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final SortedSet<E> ss;
 
         CheckedSortedSet(SortedSet<E> s, Class<E> type) {
@@ -3387,6 +3408,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -5429120189805438922L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final NavigableSet<E> ns;
 
         CheckedNavigableSet(NavigableSet<E> s, Class<E> type) {
@@ -3470,6 +3492,7 @@
     {
         @java.io.Serial
         private static final long serialVersionUID = 65247728283967356L;
+        @SuppressWarnings("serial") // Conditionally serializable
         final List<E> list;
 
         CheckedList(List<E> list, Class<E> type) {
@@ -3619,8 +3642,11 @@
         @java.io.Serial
         private static final long serialVersionUID = 5742860141034234728L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final Map<K, V> m;
+        @SuppressWarnings("serial") // Conditionally serializable
         final Class<K> keyType;
+        @SuppressWarnings("serial") // Conditionally serializable
         final Class<V> valueType;
 
         private void typeCheck(Object key, Object value) {
@@ -4019,6 +4045,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 1599671320688067438L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final SortedMap<K, V> sm;
 
         CheckedSortedMap(SortedMap<K, V> m,
@@ -4094,6 +4121,7 @@
         @java.io.Serial
         private static final long serialVersionUID = -4852462692372534096L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final NavigableMap<K, V> nm;
 
         CheckedNavigableMap(NavigableMap<K, V> m,
@@ -4825,6 +4853,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 3193687207550431679L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final E element;
 
         SingletonSet(E e) {element = e;}
@@ -4879,6 +4908,7 @@
         @java.io.Serial
         private static final long serialVersionUID = 3093736618740652951L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final E element;
 
         SingletonList(E obj)                {element = obj;}
@@ -4948,7 +4978,9 @@
         @java.io.Serial
         private static final long serialVersionUID = -6979724477215052911L;
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final K k;
+        @SuppressWarnings("serial") // Conditionally serializable
         private final V v;
 
         SingletonMap(K key, V value) {
@@ -5087,6 +5119,7 @@
         private static final long serialVersionUID = 2739099268398711800L;
 
         final int n;
+        @SuppressWarnings("serial") // Conditionally serializable
         final E element;
 
         CopiesList(int n, E e) {
@@ -5320,6 +5353,7 @@
          *
          * @serial
          */
+        @SuppressWarnings("serial") // Conditionally serializable
         final Comparator<T> cmp;
 
         ReverseComparator2(Comparator<T> cmp) {
@@ -5601,6 +5635,7 @@
     private static class SetFromMap<E> extends AbstractSet<E>
         implements Set<E>, Serializable
     {
+        @SuppressWarnings("serial") // Conditionally serializable
         private final Map<E, Boolean> m;  // The backing map
         private transient Set<E> s;       // Its keySet
 
@@ -5686,6 +5721,7 @@
         implements Queue<E>, Serializable {
         @java.io.Serial
         private static final long serialVersionUID = 1802017725587941708L;
+        @SuppressWarnings("serial") // Conditionally serializable
         private final Deque<E> q;
         AsLIFOQueue(Deque<E> q)                     { this.q = q; }
         public boolean add(E e)                     { q.addFirst(e); return true; }
--- a/src/java.base/share/classes/java/util/Comparators.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/Comparators.java	Wed Oct 09 10:17:50 2019 -0700
@@ -66,6 +66,7 @@
         private static final long serialVersionUID = -7569533591570686392L;
         private final boolean nullFirst;
         // if null, non-null Ts are considered equal
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         private final Comparator<T> real;
 
         @SuppressWarnings("unchecked")
--- a/src/java.base/share/classes/java/util/PriorityQueue.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/PriorityQueue.java	Wed Oct 09 10:17:50 2019 -0700
@@ -111,6 +111,7 @@
      * The comparator, or null if priority queue uses elements'
      * natural ordering.
      */
+    @SuppressWarnings("serial") // Conditionally serializable
     private final Comparator<? super E> comparator;
 
     /**
--- a/src/java.base/share/classes/java/util/TreeMap.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/TreeMap.java	Wed Oct 09 10:17:50 2019 -0700
@@ -118,6 +118,7 @@
      *
      * @serial
      */
+    @SuppressWarnings("serial") // Conditionally serializable
     private final Comparator<? super K> comparator;
 
     private transient Entry<K,V> root;
@@ -1353,7 +1354,10 @@
          * if loInclusive is true, lo is the inclusive bound, else lo
          * is the exclusive bound. Similarly for the upper bound.
          */
-        final K lo, hi;
+        @SuppressWarnings("serial") // Conditionally serializable
+        final K lo;
+        @SuppressWarnings("serial") // Conditionally serializable
+        final K hi;
         final boolean fromStart, toEnd;
         final boolean loInclusive, hiInclusive;
 
@@ -1936,6 +1940,7 @@
             super(m, fromStart, lo, loInclusive, toEnd, hi, hiInclusive);
         }
 
+        @SuppressWarnings("serial") // Conditionally serializable
         private final Comparator<? super K> reverseComparator =
             Collections.reverseOrder(m.comparator);
 
@@ -2024,7 +2029,10 @@
         @java.io.Serial
         private static final long serialVersionUID = -6520786458950516097L;
         private boolean fromStart = false, toEnd = false;
-        private K fromKey, toKey;
+        @SuppressWarnings("serial") // Conditionally serializable
+        private K fromKey;
+        @SuppressWarnings("serial") // Conditionally serializable
+        private K toKey;
         @java.io.Serial
         private Object readResolve() {
             return new AscendingSubMap<>(TreeMap.this,
--- a/src/java.base/share/classes/java/util/Vector.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/Vector.java	Wed Oct 09 10:17:50 2019 -0700
@@ -102,6 +102,7 @@
      *
      * @serial
      */
+    @SuppressWarnings("serial") // Conditionally serializable
     protected Object[] elementData;
 
     /**
--- a/src/java.base/share/classes/java/util/jar/JarVerifier.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/java/util/jar/JarVerifier.java	Wed Oct 09 10:17:50 2019 -0700
@@ -590,6 +590,7 @@
         URL vlocation;
         CodeSigner[] vsigners;
         java.security.cert.Certificate[] vcerts;
+        @SuppressWarnings("serial") // Not statically typed as Serializable
         Object csdomain;
 
         VerifierCodeSource(Object csdomain, URL location, CodeSigner[] signers) {
--- a/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java	Wed Oct 09 10:17:50 2019 -0700
@@ -49,6 +49,7 @@
     private static final long serialVersionUID = 100L;
     private static final PlatformLogger logger = HttpURLConnection.getHttpLogger();
 
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     private final HttpCallerInfo hci;
 
     // These maps are used to manage the GSS availability for diffrent
@@ -67,6 +68,7 @@
     }
 
     // The HTTP Negotiate Helper
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     private Negotiator negotiator = null;
 
    /**
--- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java	Wed Oct 09 10:17:50 2019 -0700
@@ -44,6 +44,7 @@
     @java.io.Serial
     private static final long serialVersionUID = 6182022883658399397L;
     private final Class<? extends Annotation> type;
+    @SuppressWarnings("serial") // Not statically typed as Serializable
     private final Map<String, Object> memberValues;
 
     AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues) {
--- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java	Wed Oct 09 09:57:41 2019 -0700
+++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationTypeMismatchExceptionProxy.java	Wed Oct 09 10:17:50 2019 -0700
@@ -36,7 +36,8 @@
 class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy {
     @java.io.Serial
     private static final long serialVersionUID = 7844069490309503934L;
-    private Method member;
+    @SuppressWarnings("serial") // Not statically typed as Serializable
+    private Method member; // Would be more robust to null-out in a writeObject method.
     private final String foundType;
 
     /**