src/share/classes/java/io/ObjectStreamClass.java

Print this page




 127     private ClassNotFoundException resolveEx;
 128     /** exception (if any) to throw if non-enum deserialization attempted */
 129     private InvalidClassException deserializeEx;
 130     /** exception (if any) to throw if non-enum serialization attempted */
 131     private InvalidClassException serializeEx;
 132     /** exception (if any) to throw if default serialization attempted */
 133     private InvalidClassException defaultSerializeEx;
 134 
 135     /** serializable fields */
 136     private ObjectStreamField[] fields;
 137     /** aggregate marshalled size of primitive fields */
 138     private int primDataSize;
 139     /** number of non-primitive fields */
 140     private int numObjFields;
 141     /** reflector for setting/getting serializable field values */
 142     private FieldReflector fieldRefl;
 143     /** data layout of serialized objects described by this class desc */
 144     private volatile ClassDataSlot[] dataLayout;
 145 
 146     /** serialization-appropriate constructor, or null if none */
 147     private Constructor cons;
 148     /** class-defined writeObject method, or null if none */
 149     private Method writeObjectMethod;
 150     /** class-defined readObject method, or null if none */
 151     private Method readObjectMethod;
 152     /** class-defined readObjectNoData method, or null if none */
 153     private Method readObjectNoDataMethod;
 154     /** class-defined writeReplace method, or null if none */
 155     private Method writeReplaceMethod;
 156     /** class-defined readResolve method, or null if none */
 157     private Method readResolveMethod;
 158 
 159     /** local class descriptor for represented class (may point to self) */
 160     private ObjectStreamClass localDesc;
 161     /** superclass descriptor appearing in stream */
 162     private ObjectStreamClass superDesc;
 163 
 164     /**
 165      * Initializes native code.
 166      */
 167     private static native void initNative();


1291     private ObjectStreamClass getVariantFor(Class<?> cl)
1292         throws InvalidClassException
1293     {
1294         if (this.cl == cl) {
1295             return this;
1296         }
1297         ObjectStreamClass desc = new ObjectStreamClass();
1298         if (isProxy) {
1299             desc.initProxy(cl, null, superDesc);
1300         } else {
1301             desc.initNonProxy(this, cl, null, superDesc);
1302         }
1303         return desc;
1304     }
1305 
1306     /**
1307      * Returns public no-arg constructor of given class, or null if none found.
1308      * Access checks are disabled on the returned constructor (if any), since
1309      * the defining class may still be non-public.
1310      */
1311     private static Constructor getExternalizableConstructor(Class<?> cl) {
1312         try {
1313             Constructor cons = cl.getDeclaredConstructor((Class<?>[]) null);
1314             cons.setAccessible(true);
1315             return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
1316                 cons : null;
1317         } catch (NoSuchMethodException ex) {
1318             return null;
1319         }
1320     }
1321 
1322     /**
1323      * Returns subclass-accessible no-arg constructor of first non-serializable
1324      * superclass, or null if none found.  Access checks are disabled on the
1325      * returned constructor (if any).
1326      */
1327     private static Constructor getSerializableConstructor(Class<?> cl) {
1328         Class<?> initCl = cl;
1329         while (Serializable.class.isAssignableFrom(initCl)) {
1330             if ((initCl = initCl.getSuperclass()) == null) {
1331                 return null;
1332             }
1333         }
1334         try {
1335             Constructor cons = initCl.getDeclaredConstructor((Class<?>[]) null);
1336             int mods = cons.getModifiers();
1337             if ((mods & Modifier.PRIVATE) != 0 ||
1338                 ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
1339                  !packageEquals(cl, initCl)))
1340             {
1341                 return null;
1342             }
1343             cons = reflFactory.newConstructorForSerialization(cl, cons);
1344             cons.setAccessible(true);
1345             return cons;
1346         } catch (NoSuchMethodException ex) {
1347             return null;
1348         }
1349     }
1350 
1351     /**
1352      * Returns non-static, non-abstract method with given signature provided it
1353      * is defined by or accessible (via inheritance) by the given class, or
1354      * null if no match found.  Access checks are disabled on the returned
1355      * method (if any).


1785      * false otherwise.
1786      */
1787     private native static boolean hasStaticInitializer(Class<?> cl);
1788 
1789     /**
1790      * Class for computing and caching field/constructor/method signatures
1791      * during serialVersionUID calculation.
1792      */
1793     private static class MemberSignature {
1794 
1795         public final Member member;
1796         public final String name;
1797         public final String signature;
1798 
1799         public MemberSignature(Field field) {
1800             member = field;
1801             name = field.getName();
1802             signature = getClassSignature(field.getType());
1803         }
1804 
1805         public MemberSignature(Constructor cons) {
1806             member = cons;
1807             name = cons.getName();
1808             signature = getMethodSignature(
1809                 cons.getParameterTypes(), Void.TYPE);
1810         }
1811 
1812         public MemberSignature(Method meth) {
1813             member = meth;
1814             name = meth.getName();
1815             signature = getMethodSignature(
1816                 meth.getParameterTypes(), meth.getReturnType());
1817         }
1818     }
1819 
1820     /**
1821      * Class for setting and retrieving serializable field values in batch.
1822      */
1823     // REMIND: dynamically generate these?
1824     private static class FieldReflector {
1825 




 127     private ClassNotFoundException resolveEx;
 128     /** exception (if any) to throw if non-enum deserialization attempted */
 129     private InvalidClassException deserializeEx;
 130     /** exception (if any) to throw if non-enum serialization attempted */
 131     private InvalidClassException serializeEx;
 132     /** exception (if any) to throw if default serialization attempted */
 133     private InvalidClassException defaultSerializeEx;
 134 
 135     /** serializable fields */
 136     private ObjectStreamField[] fields;
 137     /** aggregate marshalled size of primitive fields */
 138     private int primDataSize;
 139     /** number of non-primitive fields */
 140     private int numObjFields;
 141     /** reflector for setting/getting serializable field values */
 142     private FieldReflector fieldRefl;
 143     /** data layout of serialized objects described by this class desc */
 144     private volatile ClassDataSlot[] dataLayout;
 145 
 146     /** serialization-appropriate constructor, or null if none */
 147     private Constructor<?> cons;
 148     /** class-defined writeObject method, or null if none */
 149     private Method writeObjectMethod;
 150     /** class-defined readObject method, or null if none */
 151     private Method readObjectMethod;
 152     /** class-defined readObjectNoData method, or null if none */
 153     private Method readObjectNoDataMethod;
 154     /** class-defined writeReplace method, or null if none */
 155     private Method writeReplaceMethod;
 156     /** class-defined readResolve method, or null if none */
 157     private Method readResolveMethod;
 158 
 159     /** local class descriptor for represented class (may point to self) */
 160     private ObjectStreamClass localDesc;
 161     /** superclass descriptor appearing in stream */
 162     private ObjectStreamClass superDesc;
 163 
 164     /**
 165      * Initializes native code.
 166      */
 167     private static native void initNative();


1291     private ObjectStreamClass getVariantFor(Class<?> cl)
1292         throws InvalidClassException
1293     {
1294         if (this.cl == cl) {
1295             return this;
1296         }
1297         ObjectStreamClass desc = new ObjectStreamClass();
1298         if (isProxy) {
1299             desc.initProxy(cl, null, superDesc);
1300         } else {
1301             desc.initNonProxy(this, cl, null, superDesc);
1302         }
1303         return desc;
1304     }
1305 
1306     /**
1307      * Returns public no-arg constructor of given class, or null if none found.
1308      * Access checks are disabled on the returned constructor (if any), since
1309      * the defining class may still be non-public.
1310      */
1311     private static Constructor<?> getExternalizableConstructor(Class<?> cl) {
1312         try {
1313             Constructor<?> cons = cl.getDeclaredConstructor((Class<?>[]) null);
1314             cons.setAccessible(true);
1315             return ((cons.getModifiers() & Modifier.PUBLIC) != 0) ?
1316                 cons : null;
1317         } catch (NoSuchMethodException ex) {
1318             return null;
1319         }
1320     }
1321 
1322     /**
1323      * Returns subclass-accessible no-arg constructor of first non-serializable
1324      * superclass, or null if none found.  Access checks are disabled on the
1325      * returned constructor (if any).
1326      */
1327     private static Constructor<?> getSerializableConstructor(Class<?> cl) {
1328         Class<?> initCl = cl;
1329         while (Serializable.class.isAssignableFrom(initCl)) {
1330             if ((initCl = initCl.getSuperclass()) == null) {
1331                 return null;
1332             }
1333         }
1334         try {
1335             Constructor<?> cons = initCl.getDeclaredConstructor((Class<?>[]) null);
1336             int mods = cons.getModifiers();
1337             if ((mods & Modifier.PRIVATE) != 0 ||
1338                 ((mods & (Modifier.PUBLIC | Modifier.PROTECTED)) == 0 &&
1339                  !packageEquals(cl, initCl)))
1340             {
1341                 return null;
1342             }
1343             cons = reflFactory.newConstructorForSerialization(cl, cons);
1344             cons.setAccessible(true);
1345             return cons;
1346         } catch (NoSuchMethodException ex) {
1347             return null;
1348         }
1349     }
1350 
1351     /**
1352      * Returns non-static, non-abstract method with given signature provided it
1353      * is defined by or accessible (via inheritance) by the given class, or
1354      * null if no match found.  Access checks are disabled on the returned
1355      * method (if any).


1785      * false otherwise.
1786      */
1787     private native static boolean hasStaticInitializer(Class<?> cl);
1788 
1789     /**
1790      * Class for computing and caching field/constructor/method signatures
1791      * during serialVersionUID calculation.
1792      */
1793     private static class MemberSignature {
1794 
1795         public final Member member;
1796         public final String name;
1797         public final String signature;
1798 
1799         public MemberSignature(Field field) {
1800             member = field;
1801             name = field.getName();
1802             signature = getClassSignature(field.getType());
1803         }
1804 
1805         public MemberSignature(Constructor<?> cons) {
1806             member = cons;
1807             name = cons.getName();
1808             signature = getMethodSignature(
1809                 cons.getParameterTypes(), Void.TYPE);
1810         }
1811 
1812         public MemberSignature(Method meth) {
1813             member = meth;
1814             name = meth.getName();
1815             signature = getMethodSignature(
1816                 meth.getParameterTypes(), meth.getReturnType());
1817         }
1818     }
1819 
1820     /**
1821      * Class for setting and retrieving serializable field values in batch.
1822      */
1823     // REMIND: dynamically generate these?
1824     private static class FieldReflector {
1825