rt/emul/compact/src/main/java/java/io/ObjectStreamClass.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 604 emul/compact/src/main/java/java/io/ObjectStreamClass.java@3fcc279c921b
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
     1 /*
     2  * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 package java.io;
    27 
    28 import java.lang.ref.Reference;
    29 import java.lang.ref.ReferenceQueue;
    30 import java.lang.ref.SoftReference;
    31 import java.lang.ref.WeakReference;
    32 import java.lang.reflect.Constructor;
    33 import java.lang.reflect.Field;
    34 import java.lang.reflect.InvocationTargetException;
    35 import java.lang.reflect.Member;
    36 import java.lang.reflect.Method;
    37 import java.lang.reflect.Modifier;
    38 import java.lang.reflect.Proxy;
    39 import java.util.ArrayList;
    40 import java.util.Arrays;
    41 import java.util.Collections;
    42 import java.util.Comparator;
    43 import java.util.HashSet;
    44 import java.util.Set;
    45 
    46 /**
    47  * Serialization's descriptor for classes.  It contains the name and
    48  * serialVersionUID of the class.  The ObjectStreamClass for a specific class
    49  * loaded in this Java VM can be found/created using the lookup method.
    50  *
    51  * <p>The algorithm to compute the SerialVersionUID is described in
    52  * <a href="../../../platform/serialization/spec/class.html#4100">Object
    53  * Serialization Specification, Section 4.6, Stream Unique Identifiers</a>.
    54  *
    55  * @author      Mike Warres
    56  * @author      Roger Riggs
    57  * @see ObjectStreamField
    58  * @see <a href="../../../platform/serialization/spec/class.html">Object Serialization Specification, Section 4, Class Descriptors</a>
    59  * @since   JDK1.1
    60  */
    61 public class ObjectStreamClass implements Serializable {
    62 
    63     /** serialPersistentFields value indicating no serializable fields */
    64     public static final ObjectStreamField[] NO_FIELDS =
    65         new ObjectStreamField[0];
    66 
    67     private static final long serialVersionUID = -6120832682080437368L;
    68     private static final ObjectStreamField[] serialPersistentFields =
    69         NO_FIELDS;
    70 
    71 
    72     /** class associated with this descriptor (if any) */
    73     private Class<?> cl;
    74     /** name of class represented by this descriptor */
    75     private String name;
    76     /** serialVersionUID of represented class (null if not computed yet) */
    77     private volatile Long suid;
    78 
    79     /** true if represents dynamic proxy class */
    80     private boolean isProxy;
    81     /** true if represents enum type */
    82     private boolean isEnum;
    83     /** true if represented class implements Serializable */
    84     private boolean serializable;
    85     /** true if represented class implements Externalizable */
    86     private boolean externalizable;
    87     /** true if desc has data written by class-defined writeObject method */
    88     private boolean hasWriteObjectData;
    89     /**
    90      * true if desc has externalizable data written in block data format; this
    91      * must be true by default to accommodate ObjectInputStream subclasses which
    92      * override readClassDescriptor() to return class descriptors obtained from
    93      * ObjectStreamClass.lookup() (see 4461737)
    94      */
    95     private boolean hasBlockExternalData = true;
    96 
    97     /** exception (if any) thrown while attempting to resolve class */
    98     private ClassNotFoundException resolveEx;
    99     /** exception (if any) to throw if non-enum deserialization attempted */
   100     private InvalidClassException deserializeEx;
   101     /** exception (if any) to throw if non-enum serialization attempted */
   102     private InvalidClassException serializeEx;
   103     /** exception (if any) to throw if default serialization attempted */
   104     private InvalidClassException defaultSerializeEx;
   105 
   106     /** serializable fields */
   107     private ObjectStreamField[] fields;
   108     /** aggregate marshalled size of primitive fields */
   109     private int primDataSize;
   110     /** number of non-primitive fields */
   111     private int numObjFields;
   112     /** reflector for setting/getting serializable field values */
   113 //    private FieldReflector fieldRefl;
   114     /** data layout of serialized objects described by this class desc */
   115     private volatile ClassDataSlot[] dataLayout;
   116 
   117     /** serialization-appropriate constructor, or null if none */
   118     private Constructor cons;
   119     /** class-defined writeObject method, or null if none */
   120     private Method writeObjectMethod;
   121     /** class-defined readObject method, or null if none */
   122     private Method readObjectMethod;
   123     /** class-defined readObjectNoData method, or null if none */
   124     private Method readObjectNoDataMethod;
   125     /** class-defined writeReplace method, or null if none */
   126     private Method writeReplaceMethod;
   127     /** class-defined readResolve method, or null if none */
   128     private Method readResolveMethod;
   129 
   130     /** local class descriptor for represented class (may point to self) */
   131     private ObjectStreamClass localDesc;
   132     /** superclass descriptor appearing in stream */
   133     private ObjectStreamClass superDesc;
   134 
   135     /**
   136      * Initializes native code.
   137      */
   138     private static native void initNative();
   139     static {
   140         initNative();
   141     }
   142 
   143     /**
   144      * Find the descriptor for a class that can be serialized.  Creates an
   145      * ObjectStreamClass instance if one does not exist yet for class. Null is
   146      * returned if the specified class does not implement java.io.Serializable
   147      * or java.io.Externalizable.
   148      *
   149      * @param   cl class for which to get the descriptor
   150      * @return  the class descriptor for the specified class
   151      */
   152     public static ObjectStreamClass lookup(Class<?> cl) {
   153         return lookup(cl, false);
   154     }
   155 
   156     /**
   157      * Returns the descriptor for any class, regardless of whether it
   158      * implements {@link Serializable}.
   159      *
   160      * @param        cl class for which to get the descriptor
   161      * @return       the class descriptor for the specified class
   162      * @since 1.6
   163      */
   164     public static ObjectStreamClass lookupAny(Class<?> cl) {
   165         return lookup(cl, true);
   166     }
   167 
   168     /**
   169      * Returns the name of the class described by this descriptor.
   170      * This method returns the name of the class in the format that
   171      * is used by the {@link Class#getName} method.
   172      *
   173      * @return a string representing the name of the class
   174      */
   175     public String getName() {
   176         return name;
   177     }
   178 
   179     /**
   180      * Return the serialVersionUID for this class.  The serialVersionUID
   181      * defines a set of classes all with the same name that have evolved from a
   182      * common root class and agree to be serialized and deserialized using a
   183      * common format.  NonSerializable classes have a serialVersionUID of 0L.
   184      *
   185      * @return  the SUID of the class described by this descriptor
   186      */
   187     public long getSerialVersionUID() {
   188         // REMIND: synchronize instead of relying on volatile?
   189         if (suid == null) {
   190             return computeDefaultSUID(cl);
   191         }
   192         return suid.longValue();
   193     }
   194 
   195     /**
   196      * Return the class in the local VM that this version is mapped to.  Null
   197      * is returned if there is no corresponding local class.
   198      *
   199      * @return  the <code>Class</code> instance that this descriptor represents
   200      */
   201     public Class<?> forClass() {
   202         return cl;
   203     }
   204 
   205     /**
   206      * Return an array of the fields of this serializable class.
   207      *
   208      * @return  an array containing an element for each persistent field of
   209      *          this class. Returns an array of length zero if there are no
   210      *          fields.
   211      * @since 1.2
   212      */
   213     public ObjectStreamField[] getFields() {
   214         return getFields(true);
   215     }
   216 
   217     /**
   218      * Get the field of this class by name.
   219      *
   220      * @param   name the name of the data field to look for
   221      * @return  The ObjectStreamField object of the named field or null if
   222      *          there is no such named field.
   223      */
   224     public ObjectStreamField getField(String name) {
   225         return getField(name, null);
   226     }
   227 
   228     /**
   229      * Return a string describing this ObjectStreamClass.
   230      */
   231     public String toString() {
   232         return name + ": static final long serialVersionUID = " +
   233             getSerialVersionUID() + "L;";
   234     }
   235 
   236     /**
   237      * Looks up and returns class descriptor for given class, or null if class
   238      * is non-serializable and "all" is set to false.
   239      *
   240      * @param   cl class to look up
   241      * @param   all if true, return descriptors for all classes; if false, only
   242      *          return descriptors for serializable classes
   243      */
   244     static ObjectStreamClass lookup(Class<?> cl, boolean all) {
   245         if (!(all || Serializable.class.isAssignableFrom(cl))) {
   246             return null;
   247         }
   248         Object entry = null;
   249         EntryFuture future = null;
   250         if (entry == null) {
   251             EntryFuture newEntry = new EntryFuture();
   252             Reference<?> newRef = new SoftReference<>(newEntry);
   253             if (entry == null) {
   254                 future = newEntry;
   255             }
   256         }
   257 
   258         if (entry instanceof ObjectStreamClass) {  // check common case first
   259             return (ObjectStreamClass) entry;
   260         }
   261         if (entry instanceof EntryFuture) {
   262             future = (EntryFuture) entry;
   263             if (true) {
   264                 /*
   265                  * Handle nested call situation described by 4803747: waiting
   266                  * for future value to be set by a lookup() call further up the
   267                  * stack will result in deadlock, so calculate and set the
   268                  * future value here instead.
   269                  */
   270                 entry = null;
   271             } else {
   272                 entry = future.get();
   273             }
   274         }
   275         if (entry == null) {
   276             try {
   277                 entry = new ObjectStreamClass(cl);
   278             } catch (Throwable th) {
   279                 entry = th;
   280             }
   281             // nested lookup call already set future
   282             entry = future.get();
   283         }
   284 
   285         if (entry instanceof ObjectStreamClass) {
   286             return (ObjectStreamClass) entry;
   287         } else if (entry instanceof RuntimeException) {
   288             throw (RuntimeException) entry;
   289         } else if (entry instanceof Error) {
   290             throw (Error) entry;
   291         } else {
   292             throw new InternalError("unexpected entry: " + entry);
   293         }
   294     }
   295 
   296     /**
   297      * Placeholder used in class descriptor and field reflector lookup tables
   298      * for an entry in the process of being initialized.  (Internal) callers
   299      * which receive an EntryFuture belonging to another thread as the result
   300      * of a lookup should call the get() method of the EntryFuture; this will
   301      * return the actual entry once it is ready for use and has been set().  To
   302      * conserve objects, EntryFutures synchronize on themselves.
   303      */
   304     private static class EntryFuture {
   305 
   306         private static final Object unset = new Object();
   307         private Object entry = unset;
   308 
   309         /**
   310          * Attempts to set the value contained by this EntryFuture.  If the
   311          * EntryFuture's value has not been set already, then the value is
   312          * saved, any callers blocked in the get() method are notified, and
   313          * true is returned.  If the value has already been set, then no saving
   314          * or notification occurs, and false is returned.
   315          */
   316         synchronized boolean set(Object entry) {
   317             if (this.entry != unset) {
   318                 return false;
   319             }
   320             this.entry = entry;
   321             notifyAll();
   322             return true;
   323         }
   324 
   325         /**
   326          * Returns the value contained by this EntryFuture, blocking if
   327          * necessary until a value is set.
   328          */
   329         synchronized Object get() {
   330             boolean interrupted = false;
   331             while (entry == unset) {
   332                 try {
   333                     wait();
   334                 } catch (InterruptedException ex) {
   335                     interrupted = true;
   336                 }
   337             }
   338             return entry;
   339         }
   340     }
   341 
   342     /**
   343      * Creates local class descriptor representing given class.
   344      */
   345     private ObjectStreamClass(final Class<?> cl) {
   346         this.cl = cl;
   347         name = cl.getName();
   348         isProxy = Proxy.isProxyClass(cl);
   349         isEnum = Enum.class.isAssignableFrom(cl);
   350         serializable = Serializable.class.isAssignableFrom(cl);
   351         externalizable = Externalizable.class.isAssignableFrom(cl);
   352 
   353         Class<?> superCl = cl.getSuperclass();
   354         superDesc = (superCl != null) ? lookup(superCl, false) : null;
   355         localDesc = this;
   356 
   357         suid = Long.valueOf(0);
   358         fields = NO_FIELDS;
   359 
   360 
   361         if (deserializeEx == null) {
   362             if (isEnum) {
   363                 deserializeEx = new InvalidClassException(name, "enum type");
   364             } else if (cons == null) {
   365                 deserializeEx = new InvalidClassException(
   366                     name, "no valid constructor");
   367             }
   368         }
   369         for (int i = 0; i < fields.length; i++) {
   370             if (fields[i].getField() == null) {
   371                 defaultSerializeEx = new InvalidClassException(
   372                     name, "unmatched serializable field(s) declared");
   373             }
   374         }
   375     }
   376 
   377     /**
   378      * Creates blank class descriptor which should be initialized via a
   379      * subsequent call to initProxy(), initNonProxy() or readNonProxy().
   380      */
   381     ObjectStreamClass() {
   382     }
   383 
   384     /**
   385      * Initializes class descriptor representing a proxy class.
   386      */
   387     void initProxy(Class<?> cl,
   388                    ClassNotFoundException resolveEx,
   389                    ObjectStreamClass superDesc)
   390         throws InvalidClassException
   391     {
   392         this.cl = cl;
   393         this.resolveEx = resolveEx;
   394         this.superDesc = superDesc;
   395         isProxy = true;
   396         serializable = true;
   397         suid = Long.valueOf(0);
   398         fields = NO_FIELDS;
   399 
   400         if (cl != null) {
   401             localDesc = lookup(cl, true);
   402             if (!localDesc.isProxy) {
   403                 throw new InvalidClassException(
   404                     "cannot bind proxy descriptor to a non-proxy class");
   405             }
   406             name = localDesc.name;
   407             externalizable = localDesc.externalizable;
   408             cons = localDesc.cons;
   409             writeReplaceMethod = localDesc.writeReplaceMethod;
   410             readResolveMethod = localDesc.readResolveMethod;
   411             deserializeEx = localDesc.deserializeEx;
   412         }
   413     }
   414 
   415     /**
   416      * Initializes class descriptor representing a non-proxy class.
   417      */
   418     void initNonProxy(ObjectStreamClass model,
   419                       Class<?> cl,
   420                       ClassNotFoundException resolveEx,
   421                       ObjectStreamClass superDesc)
   422         throws InvalidClassException
   423     {
   424         this.cl = cl;
   425         this.resolveEx = resolveEx;
   426         this.superDesc = superDesc;
   427         name = model.name;
   428         suid = Long.valueOf(model.getSerialVersionUID());
   429         isProxy = false;
   430         isEnum = model.isEnum;
   431         serializable = model.serializable;
   432         externalizable = model.externalizable;
   433         hasBlockExternalData = model.hasBlockExternalData;
   434         hasWriteObjectData = model.hasWriteObjectData;
   435         fields = model.fields;
   436         primDataSize = model.primDataSize;
   437         numObjFields = model.numObjFields;
   438 
   439         if (cl != null) {
   440             localDesc = lookup(cl, true);
   441             if (localDesc.isProxy) {
   442                 throw new InvalidClassException(
   443                     "cannot bind non-proxy descriptor to a proxy class");
   444             }
   445             if (isEnum != localDesc.isEnum) {
   446                 throw new InvalidClassException(isEnum ?
   447                     "cannot bind enum descriptor to a non-enum class" :
   448                     "cannot bind non-enum descriptor to an enum class");
   449             }
   450 
   451             if (serializable == localDesc.serializable &&
   452                 !cl.isArray() &&
   453                 suid.longValue() != localDesc.getSerialVersionUID())
   454             {
   455                 throw new InvalidClassException(localDesc.name,
   456                     "local class incompatible: " +
   457                     "stream classdesc serialVersionUID = " + suid +
   458                     ", local class serialVersionUID = " +
   459                     localDesc.getSerialVersionUID());
   460             }
   461 
   462             if (!classNamesEqual(name, localDesc.name)) {
   463                 throw new InvalidClassException(localDesc.name,
   464                     "local class name incompatible with stream class " +
   465                     "name \"" + name + "\"");
   466             }
   467 
   468             if (!isEnum) {
   469                 if ((serializable == localDesc.serializable) &&
   470                     (externalizable != localDesc.externalizable))
   471                 {
   472                     throw new InvalidClassException(localDesc.name,
   473                         "Serializable incompatible with Externalizable");
   474                 }
   475 
   476                 if ((serializable != localDesc.serializable) ||
   477                     (externalizable != localDesc.externalizable) ||
   478                     !(serializable || externalizable))
   479                 {
   480                     deserializeEx = new InvalidClassException(localDesc.name,
   481                         "class invalid for deserialization");
   482                 }
   483             }
   484 
   485             cons = localDesc.cons;
   486             writeObjectMethod = localDesc.writeObjectMethod;
   487             readObjectMethod = localDesc.readObjectMethod;
   488             readObjectNoDataMethod = localDesc.readObjectNoDataMethod;
   489             writeReplaceMethod = localDesc.writeReplaceMethod;
   490             readResolveMethod = localDesc.readResolveMethod;
   491             if (deserializeEx == null) {
   492                 deserializeEx = localDesc.deserializeEx;
   493             }
   494         }
   495         // reassign to matched fields so as to reflect local unshared settings
   496         fields = null;
   497     }
   498 
   499     /**
   500      * Reads non-proxy class descriptor information from given input stream.
   501      * The resulting class descriptor is not fully functional; it can only be
   502      * used as input to the ObjectInputStream.resolveClass() and
   503      * ObjectStreamClass.initNonProxy() methods.
   504      */
   505     void readNonProxy(ObjectInputStream in)
   506         throws IOException, ClassNotFoundException
   507     {
   508         name = in.readUTF();
   509         suid = Long.valueOf(in.readLong());
   510         isProxy = false;
   511 
   512         byte flags = in.readByte();
   513         hasWriteObjectData =
   514             ((flags & ObjectStreamConstants.SC_WRITE_METHOD) != 0);
   515         hasBlockExternalData =
   516             ((flags & ObjectStreamConstants.SC_BLOCK_DATA) != 0);
   517         externalizable =
   518             ((flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0);
   519         boolean sflag =
   520             ((flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0);
   521         if (externalizable && sflag) {
   522             throw new InvalidClassException(
   523                 name, "serializable and externalizable flags conflict");
   524         }
   525         serializable = externalizable || sflag;
   526         isEnum = ((flags & ObjectStreamConstants.SC_ENUM) != 0);
   527         if (isEnum && suid.longValue() != 0L) {
   528             throw new InvalidClassException(name,
   529                 "enum descriptor has non-zero serialVersionUID: " + suid);
   530         }
   531 
   532         int numFields = in.readShort();
   533         if (isEnum && numFields != 0) {
   534             throw new InvalidClassException(name,
   535                 "enum descriptor has non-zero field count: " + numFields);
   536         }
   537         fields = (numFields > 0) ?
   538             new ObjectStreamField[numFields] : NO_FIELDS;
   539         for (int i = 0; i < numFields; i++) {
   540             char tcode = (char) in.readByte();
   541             String fname = in.readUTF();
   542             String signature = ((tcode == 'L') || (tcode == '[')) ?
   543                 in.readTypeString() : new String(new char[] { tcode });
   544             try {
   545                 fields[i] = new ObjectStreamField(fname, signature, false);
   546             } catch (RuntimeException e) {
   547                 throw (IOException) new InvalidClassException(name,
   548                     "invalid descriptor for field " + fname).initCause(e);
   549             }
   550         }
   551         computeFieldOffsets();
   552     }
   553 
   554     /**
   555      * Writes non-proxy class descriptor information to given output stream.
   556      */
   557     void writeNonProxy(ObjectOutputStream out) throws IOException {
   558         out.writeUTF(name);
   559         out.writeLong(getSerialVersionUID());
   560 
   561         byte flags = 0;
   562         if (externalizable) {
   563             flags |= ObjectStreamConstants.SC_EXTERNALIZABLE;
   564             int protocol = out.getProtocolVersion();
   565             if (protocol != ObjectStreamConstants.PROTOCOL_VERSION_1) {
   566                 flags |= ObjectStreamConstants.SC_BLOCK_DATA;
   567             }
   568         } else if (serializable) {
   569             flags |= ObjectStreamConstants.SC_SERIALIZABLE;
   570         }
   571         if (hasWriteObjectData) {
   572             flags |= ObjectStreamConstants.SC_WRITE_METHOD;
   573         }
   574         if (isEnum) {
   575             flags |= ObjectStreamConstants.SC_ENUM;
   576         }
   577         out.writeByte(flags);
   578 
   579         out.writeShort(fields.length);
   580         for (int i = 0; i < fields.length; i++) {
   581             ObjectStreamField f = fields[i];
   582             out.writeByte(f.getTypeCode());
   583             out.writeUTF(f.getName());
   584             if (!f.isPrimitive()) {
   585                 out.writeTypeString(f.getTypeString());
   586             }
   587         }
   588     }
   589 
   590     /**
   591      * Returns ClassNotFoundException (if any) thrown while attempting to
   592      * resolve local class corresponding to this class descriptor.
   593      */
   594     ClassNotFoundException getResolveException() {
   595         return resolveEx;
   596     }
   597 
   598     /**
   599      * Throws an InvalidClassException if object instances referencing this
   600      * class descriptor should not be allowed to deserialize.  This method does
   601      * not apply to deserialization of enum constants.
   602      */
   603     void checkDeserialize() throws InvalidClassException {
   604         if (deserializeEx != null) {
   605             InvalidClassException ice =
   606                 new InvalidClassException(deserializeEx.classname,
   607                                           deserializeEx.getMessage());
   608             ice.initCause(deserializeEx);
   609             throw ice;
   610         }
   611     }
   612 
   613     /**
   614      * Throws an InvalidClassException if objects whose class is represented by
   615      * this descriptor should not be allowed to serialize.  This method does
   616      * not apply to serialization of enum constants.
   617      */
   618     void checkSerialize() throws InvalidClassException {
   619         if (serializeEx != null) {
   620             InvalidClassException ice =
   621                 new InvalidClassException(serializeEx.classname,
   622                                           serializeEx.getMessage());
   623             ice.initCause(serializeEx);
   624             throw ice;
   625         }
   626     }
   627 
   628     /**
   629      * Throws an InvalidClassException if objects whose class is represented by
   630      * this descriptor should not be permitted to use default serialization
   631      * (e.g., if the class declares serializable fields that do not correspond
   632      * to actual fields, and hence must use the GetField API).  This method
   633      * does not apply to deserialization of enum constants.
   634      */
   635     void checkDefaultSerialize() throws InvalidClassException {
   636         if (defaultSerializeEx != null) {
   637             InvalidClassException ice =
   638                 new InvalidClassException(defaultSerializeEx.classname,
   639                                           defaultSerializeEx.getMessage());
   640             ice.initCause(defaultSerializeEx);
   641             throw ice;
   642         }
   643     }
   644 
   645     /**
   646      * Returns superclass descriptor.  Note that on the receiving side, the
   647      * superclass descriptor may be bound to a class that is not a superclass
   648      * of the subclass descriptor's bound class.
   649      */
   650     ObjectStreamClass getSuperDesc() {
   651         return superDesc;
   652     }
   653 
   654     /**
   655      * Returns the "local" class descriptor for the class associated with this
   656      * class descriptor (i.e., the result of
   657      * ObjectStreamClass.lookup(this.forClass())) or null if there is no class
   658      * associated with this descriptor.
   659      */
   660     ObjectStreamClass getLocalDesc() {
   661         return localDesc;
   662     }
   663 
   664     /**
   665      * Returns arrays of ObjectStreamFields representing the serializable
   666      * fields of the represented class.  If copy is true, a clone of this class
   667      * descriptor's field array is returned, otherwise the array itself is
   668      * returned.
   669      */
   670     ObjectStreamField[] getFields(boolean copy) {
   671         return copy ? fields.clone() : fields;
   672     }
   673 
   674     /**
   675      * Looks up a serializable field of the represented class by name and type.
   676      * A specified type of null matches all types, Object.class matches all
   677      * non-primitive types, and any other non-null type matches assignable
   678      * types only.  Returns matching field, or null if no match found.
   679      */
   680     ObjectStreamField getField(String name, Class<?> type) {
   681         for (int i = 0; i < fields.length; i++) {
   682             ObjectStreamField f = fields[i];
   683             if (f.getName().equals(name)) {
   684                 if (type == null ||
   685                     (type == Object.class && !f.isPrimitive()))
   686                 {
   687                     return f;
   688                 }
   689                 Class<?> ftype = f.getType();
   690                 if (ftype != null && type.isAssignableFrom(ftype)) {
   691                     return f;
   692                 }
   693             }
   694         }
   695         return null;
   696     }
   697 
   698     /**
   699      * Returns true if class descriptor represents a dynamic proxy class, false
   700      * otherwise.
   701      */
   702     boolean isProxy() {
   703         return isProxy;
   704     }
   705 
   706     /**
   707      * Returns true if class descriptor represents an enum type, false
   708      * otherwise.
   709      */
   710     boolean isEnum() {
   711         return isEnum;
   712     }
   713 
   714     /**
   715      * Returns true if represented class implements Externalizable, false
   716      * otherwise.
   717      */
   718     boolean isExternalizable() {
   719         return externalizable;
   720     }
   721 
   722     /**
   723      * Returns true if represented class implements Serializable, false
   724      * otherwise.
   725      */
   726     boolean isSerializable() {
   727         return serializable;
   728     }
   729 
   730     /**
   731      * Returns true if class descriptor represents externalizable class that
   732      * has written its data in 1.2 (block data) format, false otherwise.
   733      */
   734     boolean hasBlockExternalData() {
   735         return hasBlockExternalData;
   736     }
   737 
   738     /**
   739      * Returns true if class descriptor represents serializable (but not
   740      * externalizable) class which has written its data via a custom
   741      * writeObject() method, false otherwise.
   742      */
   743     boolean hasWriteObjectData() {
   744         return hasWriteObjectData;
   745     }
   746 
   747     /**
   748      * Returns true if represented class is serializable/externalizable and can
   749      * be instantiated by the serialization runtime--i.e., if it is
   750      * externalizable and defines a public no-arg constructor, or if it is
   751      * non-externalizable and its first non-serializable superclass defines an
   752      * accessible no-arg constructor.  Otherwise, returns false.
   753      */
   754     boolean isInstantiable() {
   755         return (cons != null);
   756     }
   757 
   758     /**
   759      * Returns true if represented class is serializable (but not
   760      * externalizable) and defines a conformant writeObject method.  Otherwise,
   761      * returns false.
   762      */
   763     boolean hasWriteObjectMethod() {
   764         return (writeObjectMethod != null);
   765     }
   766 
   767     /**
   768      * Returns true if represented class is serializable (but not
   769      * externalizable) and defines a conformant readObject method.  Otherwise,
   770      * returns false.
   771      */
   772     boolean hasReadObjectMethod() {
   773         return (readObjectMethod != null);
   774     }
   775 
   776     /**
   777      * Returns true if represented class is serializable (but not
   778      * externalizable) and defines a conformant readObjectNoData method.
   779      * Otherwise, returns false.
   780      */
   781     boolean hasReadObjectNoDataMethod() {
   782         return (readObjectNoDataMethod != null);
   783     }
   784 
   785     /**
   786      * Returns true if represented class is serializable or externalizable and
   787      * defines a conformant writeReplace method.  Otherwise, returns false.
   788      */
   789     boolean hasWriteReplaceMethod() {
   790         return (writeReplaceMethod != null);
   791     }
   792 
   793     /**
   794      * Returns true if represented class is serializable or externalizable and
   795      * defines a conformant readResolve method.  Otherwise, returns false.
   796      */
   797     boolean hasReadResolveMethod() {
   798         return (readResolveMethod != null);
   799     }
   800 
   801     /**
   802      * Creates a new instance of the represented class.  If the class is
   803      * externalizable, invokes its public no-arg constructor; otherwise, if the
   804      * class is serializable, invokes the no-arg constructor of the first
   805      * non-serializable superclass.  Throws UnsupportedOperationException if
   806      * this class descriptor is not associated with a class, if the associated
   807      * class is non-serializable or if the appropriate no-arg constructor is
   808      * inaccessible/unavailable.
   809      */
   810     Object newInstance()
   811         throws InstantiationException, InvocationTargetException,
   812                UnsupportedOperationException
   813     {
   814         if (cons != null) {
   815             try {
   816                 return cons.newInstance();
   817             } catch (IllegalAccessException ex) {
   818                 // should not occur, as access checks have been suppressed
   819                 throw new InternalError();
   820             }
   821         } else {
   822             throw new UnsupportedOperationException();
   823         }
   824     }
   825 
   826     /**
   827      * Invokes the writeObject method of the represented serializable class.
   828      * Throws UnsupportedOperationException if this class descriptor is not
   829      * associated with a class, or if the class is externalizable,
   830      * non-serializable or does not define writeObject.
   831      */
   832     void invokeWriteObject(Object obj, ObjectOutputStream out)
   833         throws IOException, UnsupportedOperationException
   834     {
   835         if (writeObjectMethod != null) {
   836             try {
   837                 writeObjectMethod.invoke(obj, new Object[]{ out });
   838             } catch (InvocationTargetException ex) {
   839                 Throwable th = ex.getTargetException();
   840                 if (th instanceof IOException) {
   841                     throw (IOException) th;
   842                 } else {
   843                     throwMiscException(th);
   844                 }
   845             } catch (IllegalAccessException ex) {
   846                 // should not occur, as access checks have been suppressed
   847                 throw new InternalError();
   848             }
   849         } else {
   850             throw new UnsupportedOperationException();
   851         }
   852     }
   853 
   854     /**
   855      * Invokes the readObject method of the represented serializable class.
   856      * Throws UnsupportedOperationException if this class descriptor is not
   857      * associated with a class, or if the class is externalizable,
   858      * non-serializable or does not define readObject.
   859      */
   860     void invokeReadObject(Object obj, ObjectInputStream in)
   861         throws ClassNotFoundException, IOException,
   862                UnsupportedOperationException
   863     {
   864         if (readObjectMethod != null) {
   865             try {
   866                 readObjectMethod.invoke(obj, new Object[]{ in });
   867             } catch (InvocationTargetException ex) {
   868                 Throwable th = ex.getTargetException();
   869                 if (th instanceof ClassNotFoundException) {
   870                     throw (ClassNotFoundException) th;
   871                 } else if (th instanceof IOException) {
   872                     throw (IOException) th;
   873                 } else {
   874                     throwMiscException(th);
   875                 }
   876             } catch (IllegalAccessException ex) {
   877                 // should not occur, as access checks have been suppressed
   878                 throw new InternalError();
   879             }
   880         } else {
   881             throw new UnsupportedOperationException();
   882         }
   883     }
   884 
   885     /**
   886      * Invokes the readObjectNoData method of the represented serializable
   887      * class.  Throws UnsupportedOperationException if this class descriptor is
   888      * not associated with a class, or if the class is externalizable,
   889      * non-serializable or does not define readObjectNoData.
   890      */
   891     void invokeReadObjectNoData(Object obj)
   892         throws IOException, UnsupportedOperationException
   893     {
   894         if (readObjectNoDataMethod != null) {
   895             try {
   896                 readObjectNoDataMethod.invoke(obj, (Object[]) null);
   897             } catch (InvocationTargetException ex) {
   898                 Throwable th = ex.getTargetException();
   899                 if (th instanceof ObjectStreamException) {
   900                     throw (ObjectStreamException) th;
   901                 } else {
   902                     throwMiscException(th);
   903                 }
   904             } catch (IllegalAccessException ex) {
   905                 // should not occur, as access checks have been suppressed
   906                 throw new InternalError();
   907             }
   908         } else {
   909             throw new UnsupportedOperationException();
   910         }
   911     }
   912 
   913     /**
   914      * Invokes the writeReplace method of the represented serializable class and
   915      * returns the result.  Throws UnsupportedOperationException if this class
   916      * descriptor is not associated with a class, or if the class is
   917      * non-serializable or does not define writeReplace.
   918      */
   919     Object invokeWriteReplace(Object obj)
   920         throws IOException, UnsupportedOperationException
   921     {
   922         if (writeReplaceMethod != null) {
   923             try {
   924                 return writeReplaceMethod.invoke(obj, (Object[]) null);
   925             } catch (InvocationTargetException ex) {
   926                 Throwable th = ex.getTargetException();
   927                 if (th instanceof ObjectStreamException) {
   928                     throw (ObjectStreamException) th;
   929                 } else {
   930                     throwMiscException(th);
   931                     throw new InternalError();  // never reached
   932                 }
   933             } catch (IllegalAccessException ex) {
   934                 // should not occur, as access checks have been suppressed
   935                 throw new InternalError();
   936             }
   937         } else {
   938             throw new UnsupportedOperationException();
   939         }
   940     }
   941 
   942     /**
   943      * Invokes the readResolve method of the represented serializable class and
   944      * returns the result.  Throws UnsupportedOperationException if this class
   945      * descriptor is not associated with a class, or if the class is
   946      * non-serializable or does not define readResolve.
   947      */
   948     Object invokeReadResolve(Object obj)
   949         throws IOException, UnsupportedOperationException
   950     {
   951         if (readResolveMethod != null) {
   952             try {
   953                 return readResolveMethod.invoke(obj, (Object[]) null);
   954             } catch (InvocationTargetException ex) {
   955                 Throwable th = ex.getTargetException();
   956                 if (th instanceof ObjectStreamException) {
   957                     throw (ObjectStreamException) th;
   958                 } else {
   959                     throwMiscException(th);
   960                     throw new InternalError();  // never reached
   961                 }
   962             } catch (IllegalAccessException ex) {
   963                 // should not occur, as access checks have been suppressed
   964                 throw new InternalError();
   965             }
   966         } else {
   967             throw new UnsupportedOperationException();
   968         }
   969     }
   970 
   971     /**
   972      * Class representing the portion of an object's serialized form allotted
   973      * to data described by a given class descriptor.  If "hasData" is false,
   974      * the object's serialized form does not contain data associated with the
   975      * class descriptor.
   976      */
   977     static class ClassDataSlot {
   978 
   979         /** class descriptor "occupying" this slot */
   980         final ObjectStreamClass desc;
   981         /** true if serialized form includes data for this slot's descriptor */
   982         final boolean hasData;
   983 
   984         ClassDataSlot(ObjectStreamClass desc, boolean hasData) {
   985             this.desc = desc;
   986             this.hasData = hasData;
   987         }
   988     }
   989 
   990     /**
   991      * Returns array of ClassDataSlot instances representing the data layout
   992      * (including superclass data) for serialized objects described by this
   993      * class descriptor.  ClassDataSlots are ordered by inheritance with those
   994      * containing "higher" superclasses appearing first.  The final
   995      * ClassDataSlot contains a reference to this descriptor.
   996      */
   997     ClassDataSlot[] getClassDataLayout() throws InvalidClassException {
   998         // REMIND: synchronize instead of relying on volatile?
   999         if (dataLayout == null) {
  1000             dataLayout = getClassDataLayout0();
  1001         }
  1002         return dataLayout;
  1003     }
  1004 
  1005     private ClassDataSlot[] getClassDataLayout0()
  1006         throws InvalidClassException
  1007     {
  1008         ArrayList<ClassDataSlot> slots = new ArrayList<>();
  1009         Class<?> start = cl, end = cl;
  1010 
  1011         // locate closest non-serializable superclass
  1012         while (end != null && Serializable.class.isAssignableFrom(end)) {
  1013             end = end.getSuperclass();
  1014         }
  1015 
  1016         for (ObjectStreamClass d = this; d != null; d = d.superDesc) {
  1017 
  1018             // search up inheritance hierarchy for class with matching name
  1019             String searchName = (d.cl != null) ? d.cl.getName() : d.name;
  1020             Class<?> match = null;
  1021             for (Class<?> c = start; c != end; c = c.getSuperclass()) {
  1022                 if (searchName.equals(c.getName())) {
  1023                     match = c;
  1024                     break;
  1025                 }
  1026             }
  1027 
  1028             // add "no data" slot for each unmatched class below match
  1029             if (match != null) {
  1030                 for (Class<?> c = start; c != match; c = c.getSuperclass()) {
  1031                     slots.add(new ClassDataSlot(
  1032                         ObjectStreamClass.lookup(c, true), false));
  1033                 }
  1034                 start = match.getSuperclass();
  1035             }
  1036 
  1037             // record descriptor/class pairing
  1038             slots.add(new ClassDataSlot(d.getVariantFor(match), true));
  1039         }
  1040 
  1041         // add "no data" slot for any leftover unmatched classes
  1042         for (Class<?> c = start; c != end; c = c.getSuperclass()) {
  1043             slots.add(new ClassDataSlot(
  1044                 ObjectStreamClass.lookup(c, true), false));
  1045         }
  1046 
  1047         // order slots from superclass -> subclass
  1048         Collections.reverse(slots);
  1049         return slots.toArray(new ClassDataSlot[slots.size()]);
  1050     }
  1051 
  1052     /**
  1053      * Returns aggregate size (in bytes) of marshalled primitive field values
  1054      * for represented class.
  1055      */
  1056     int getPrimDataSize() {
  1057         return primDataSize;
  1058     }
  1059 
  1060     /**
  1061      * Returns number of non-primitive serializable fields of represented
  1062      * class.
  1063      */
  1064     int getNumObjFields() {
  1065         return numObjFields;
  1066     }
  1067 
  1068     /**
  1069      * Fetches the serializable primitive field values of object obj and
  1070      * marshals them into byte array buf starting at offset 0.  It is the
  1071      * responsibility of the caller to ensure that obj is of the proper type if
  1072      * non-null.
  1073      */
  1074     void getPrimFieldValues(Object obj, byte[] buf) {
  1075     }
  1076 
  1077     /**
  1078      * Sets the serializable primitive fields of object obj using values
  1079      * unmarshalled from byte array buf starting at offset 0.  It is the
  1080      * responsibility of the caller to ensure that obj is of the proper type if
  1081      * non-null.
  1082      */
  1083     void setPrimFieldValues(Object obj, byte[] buf) {
  1084     }
  1085 
  1086     /**
  1087      * Fetches the serializable object field values of object obj and stores
  1088      * them in array vals starting at offset 0.  It is the responsibility of
  1089      * the caller to ensure that obj is of the proper type if non-null.
  1090      */
  1091     void getObjFieldValues(Object obj, Object[] vals) {
  1092     }
  1093 
  1094     /**
  1095      * Sets the serializable object fields of object obj using values from
  1096      * array vals starting at offset 0.  It is the responsibility of the caller
  1097      * to ensure that obj is of the proper type if non-null.
  1098      */
  1099     void setObjFieldValues(Object obj, Object[] vals) {
  1100     }
  1101 
  1102     /**
  1103      * Calculates and sets serializable field offsets, as well as primitive
  1104      * data size and object field count totals.  Throws InvalidClassException
  1105      * if fields are illegally ordered.
  1106      */
  1107     private void computeFieldOffsets() throws InvalidClassException {
  1108         primDataSize = 0;
  1109         numObjFields = 0;
  1110         int firstObjIndex = -1;
  1111 
  1112         for (int i = 0; i < fields.length; i++) {
  1113             ObjectStreamField f = fields[i];
  1114             switch (f.getTypeCode()) {
  1115                 case 'Z':
  1116                 case 'B':
  1117                     f.setOffset(primDataSize++);
  1118                     break;
  1119 
  1120                 case 'C':
  1121                 case 'S':
  1122                     f.setOffset(primDataSize);
  1123                     primDataSize += 2;
  1124                     break;
  1125 
  1126                 case 'I':
  1127                 case 'F':
  1128                     f.setOffset(primDataSize);
  1129                     primDataSize += 4;
  1130                     break;
  1131 
  1132                 case 'J':
  1133                 case 'D':
  1134                     f.setOffset(primDataSize);
  1135                     primDataSize += 8;
  1136                     break;
  1137 
  1138                 case '[':
  1139                 case 'L':
  1140                     f.setOffset(numObjFields++);
  1141                     if (firstObjIndex == -1) {
  1142                         firstObjIndex = i;
  1143                     }
  1144                     break;
  1145 
  1146                 default:
  1147                     throw new InternalError();
  1148             }
  1149         }
  1150         if (firstObjIndex != -1 &&
  1151             firstObjIndex + numObjFields != fields.length)
  1152         {
  1153             throw new InvalidClassException(name, "illegal field order");
  1154         }
  1155     }
  1156 
  1157     /**
  1158      * If given class is the same as the class associated with this class
  1159      * descriptor, returns reference to this class descriptor.  Otherwise,
  1160      * returns variant of this class descriptor bound to given class.
  1161      */
  1162     private ObjectStreamClass getVariantFor(Class<?> cl)
  1163         throws InvalidClassException
  1164     {
  1165         if (this.cl == cl) {
  1166             return this;
  1167         }
  1168         ObjectStreamClass desc = new ObjectStreamClass();
  1169         if (isProxy) {
  1170             desc.initProxy(cl, null, superDesc);
  1171         } else {
  1172             desc.initNonProxy(this, cl, null, superDesc);
  1173         }
  1174         return desc;
  1175     }
  1176 
  1177     /**
  1178      * Returns public no-arg constructor of given class, or null if none found.
  1179      * Access checks are disabled on the returned constructor (if any), since
  1180      * the defining class may still be non-public.
  1181      */
  1182     private static Constructor getExternalizableConstructor(Class<?> cl) {
  1183         throw new SecurityException();
  1184     }
  1185 
  1186     /**
  1187      * Returns subclass-accessible no-arg constructor of first non-serializable
  1188      * superclass, or null if none found.  Access checks are disabled on the
  1189      * returned constructor (if any).
  1190      */
  1191     private static Constructor getSerializableConstructor(Class<?> cl) {
  1192         Class<?> initCl = cl;
  1193         while (Serializable.class.isAssignableFrom(initCl)) {
  1194             if ((initCl = initCl.getSuperclass()) == null) {
  1195                 return null;
  1196             }
  1197         }
  1198         throw new SecurityException();
  1199     }
  1200 
  1201     /**
  1202      * Returns non-static, non-abstract method with given signature provided it
  1203      * is defined by or accessible (via inheritance) by the given class, or
  1204      * null if no match found.  Access checks are disabled on the returned
  1205      * method (if any).
  1206      */
  1207     private static Method getInheritableMethod(Class<?> cl, String name,
  1208                                                Class<?>[] argTypes,
  1209                                                Class<?> returnType)
  1210     {
  1211         throw new SecurityException();
  1212     }
  1213 
  1214     /**
  1215      * Returns non-static private method with given signature defined by given
  1216      * class, or null if none found.  Access checks are disabled on the
  1217      * returned method (if any).
  1218      */
  1219     private static Method getPrivateMethod(Class<?> cl, String name,
  1220                                            Class<?>[] argTypes,
  1221                                            Class<?> returnType)
  1222     {
  1223         throw new SecurityException();
  1224     }
  1225 
  1226     /**
  1227      * Returns true if classes are defined in the same runtime package, false
  1228      * otherwise.
  1229      */
  1230     private static boolean packageEquals(Class<?> cl1, Class<?> cl2) {
  1231         return (cl1.getClassLoader() == cl2.getClassLoader() &&
  1232                 getPackageName(cl1).equals(getPackageName(cl2)));
  1233     }
  1234 
  1235     /**
  1236      * Returns package name of given class.
  1237      */
  1238     private static String getPackageName(Class<?> cl) {
  1239         String s = cl.getName();
  1240         int i = s.lastIndexOf('[');
  1241         if (i >= 0) {
  1242             s = s.substring(i + 2);
  1243         }
  1244         i = s.lastIndexOf('.');
  1245         return (i >= 0) ? s.substring(0, i) : "";
  1246     }
  1247 
  1248     /**
  1249      * Compares class names for equality, ignoring package names.  Returns true
  1250      * if class names equal, false otherwise.
  1251      */
  1252     private static boolean classNamesEqual(String name1, String name2) {
  1253         name1 = name1.substring(name1.lastIndexOf('.') + 1);
  1254         name2 = name2.substring(name2.lastIndexOf('.') + 1);
  1255         return name1.equals(name2);
  1256     }
  1257 
  1258     /**
  1259      * Returns JVM type signature for given class.
  1260      */
  1261     private static String getClassSignature(Class<?> cl) {
  1262         StringBuilder sbuf = new StringBuilder();
  1263         while (cl.isArray()) {
  1264             sbuf.append('[');
  1265             cl = cl.getComponentType();
  1266         }
  1267         if (cl.isPrimitive()) {
  1268             if (cl == Integer.TYPE) {
  1269                 sbuf.append('I');
  1270             } else if (cl == Byte.TYPE) {
  1271                 sbuf.append('B');
  1272             } else if (cl == Long.TYPE) {
  1273                 sbuf.append('J');
  1274             } else if (cl == Float.TYPE) {
  1275                 sbuf.append('F');
  1276             } else if (cl == Double.TYPE) {
  1277                 sbuf.append('D');
  1278             } else if (cl == Short.TYPE) {
  1279                 sbuf.append('S');
  1280             } else if (cl == Character.TYPE) {
  1281                 sbuf.append('C');
  1282             } else if (cl == Boolean.TYPE) {
  1283                 sbuf.append('Z');
  1284             } else if (cl == Void.TYPE) {
  1285                 sbuf.append('V');
  1286             } else {
  1287                 throw new InternalError();
  1288             }
  1289         } else {
  1290             sbuf.append('L' + cl.getName().replace('.', '/') + ';');
  1291         }
  1292         return sbuf.toString();
  1293     }
  1294 
  1295     /**
  1296      * Returns JVM type signature for given list of parameters and return type.
  1297      */
  1298     private static String getMethodSignature(Class<?>[] paramTypes,
  1299                                              Class<?> retType)
  1300     {
  1301         StringBuilder sbuf = new StringBuilder();
  1302         sbuf.append('(');
  1303         for (int i = 0; i < paramTypes.length; i++) {
  1304             sbuf.append(getClassSignature(paramTypes[i]));
  1305         }
  1306         sbuf.append(')');
  1307         sbuf.append(getClassSignature(retType));
  1308         return sbuf.toString();
  1309     }
  1310 
  1311     /**
  1312      * Convenience method for throwing an exception that is either a
  1313      * RuntimeException, Error, or of some unexpected type (in which case it is
  1314      * wrapped inside an IOException).
  1315      */
  1316     private static void throwMiscException(Throwable th) throws IOException {
  1317         if (th instanceof RuntimeException) {
  1318             throw (RuntimeException) th;
  1319         } else if (th instanceof Error) {
  1320             throw (Error) th;
  1321         } else {
  1322             IOException ex = new IOException("unexpected exception type");
  1323             ex.initCause(th);
  1324             throw ex;
  1325         }
  1326     }
  1327 
  1328     /**
  1329      * Returns ObjectStreamField array describing the serializable fields of
  1330      * the given class.  Serializable fields backed by an actual field of the
  1331      * class are represented by ObjectStreamFields with corresponding non-null
  1332      * Field objects.  Throws InvalidClassException if the (explicitly
  1333      * declared) serializable fields are invalid.
  1334      */
  1335     private static ObjectStreamField[] getSerialFields(Class<?> cl)
  1336         throws InvalidClassException
  1337     {
  1338         ObjectStreamField[] fields;
  1339         if (Serializable.class.isAssignableFrom(cl) &&
  1340             !Externalizable.class.isAssignableFrom(cl) &&
  1341             !Proxy.isProxyClass(cl) &&
  1342             !cl.isInterface())
  1343         {
  1344             if ((fields = getDeclaredSerialFields(cl)) == null) {
  1345                 fields = getDefaultSerialFields(cl);
  1346             }
  1347             Arrays.sort(fields);
  1348         } else {
  1349             fields = NO_FIELDS;
  1350         }
  1351         return fields;
  1352     }
  1353 
  1354     /**
  1355      * Returns serializable fields of given class as defined explicitly by a
  1356      * "serialPersistentFields" field, or null if no appropriate
  1357      * "serialPersistentFields" field is defined.  Serializable fields backed
  1358      * by an actual field of the class are represented by ObjectStreamFields
  1359      * with corresponding non-null Field objects.  For compatibility with past
  1360      * releases, a "serialPersistentFields" field with a null value is
  1361      * considered equivalent to not declaring "serialPersistentFields".  Throws
  1362      * InvalidClassException if the declared serializable fields are
  1363      * invalid--e.g., if multiple fields share the same name.
  1364      */
  1365     private static ObjectStreamField[] getDeclaredSerialFields(Class<?> cl)
  1366         throws InvalidClassException
  1367     {
  1368         throw new SecurityException();
  1369     }
  1370 
  1371     /**
  1372      * Returns array of ObjectStreamFields corresponding to all non-static
  1373      * non-transient fields declared by given class.  Each ObjectStreamField
  1374      * contains a Field object for the field it represents.  If no default
  1375      * serializable fields exist, NO_FIELDS is returned.
  1376      */
  1377     private static ObjectStreamField[] getDefaultSerialFields(Class<?> cl) {
  1378         throw new SecurityException();
  1379     }
  1380 
  1381     /**
  1382      * Returns explicit serial version UID value declared by given class, or
  1383      * null if none.
  1384      */
  1385     private static Long getDeclaredSUID(Class<?> cl) {
  1386         return null;
  1387     }
  1388 
  1389     /**
  1390      * Computes the default serial version UID value for the given class.
  1391      */
  1392     private static long computeDefaultSUID(Class<?> cl) {
  1393         throw new SecurityException();
  1394     }
  1395 
  1396 }