2165 if (cl == String.class || cl == Class.class
2166 || cl == ObjectStreamClass.class) {
2167 throw new InvalidClassException("invalid class descriptor");
2168 }
2169
2170 Object obj;
2171 try {
2172 obj = desc.isInstantiable() ? desc.newInstance() : null;
2173 } catch (Exception ex) {
2174 throw (IOException) new InvalidClassException(
2175 desc.forClass().getName(),
2176 "unable to create instance").initCause(ex);
2177 }
2178
2179 passHandle = handles.assign(unshared ? unsharedMarker : obj);
2180 ClassNotFoundException resolveEx = desc.getResolveException();
2181 if (resolveEx != null) {
2182 handles.markException(passHandle, resolveEx);
2183 }
2184
2185 final boolean isRecord = cl != null && isRecord(cl) ? true : false;
2186 if (isRecord) {
2187 assert obj == null;
2188 obj = readRecord(desc);
2189 if (!unshared)
2190 handles.setObject(passHandle, obj);
2191 } else if (desc.isExternalizable()) {
2192 readExternalData((Externalizable) obj, desc);
2193 } else {
2194 readSerialData(obj, desc);
2195 }
2196
2197 handles.finish(passHandle);
2198
2199 if (obj != null &&
2200 handles.lookupException(passHandle) == null &&
2201 desc.hasReadResolveMethod())
2202 {
2203 Object rep = desc.invokeReadResolve(obj);
2204 if (unshared && rep.getClass().isArray()) {
2205 rep = cloneArray(rep);
2272 * externalizable data remains in the stream, a subsequent read will
2273 * most likely throw a StreamCorruptedException.
2274 */
2275 }
2276
2277 /** Reads a record. */
2278 private Object readRecord(ObjectStreamClass desc) throws IOException {
2279 ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
2280 if (slots.length != 1) {
2281 // skip any superclass stream field values
2282 for (int i = 0; i < slots.length-1; i++) {
2283 ObjectStreamClass slotDesc = slots[i].desc;
2284 if (slots[i].hasData) {
2285 defaultReadFields(null, slotDesc);
2286 }
2287 }
2288 }
2289
2290 FieldValues fieldValues = defaultReadFields(null, desc);
2291
2292 // retrieve the canonical constructor
2293 MethodHandle ctrMH = desc.getRecordConstructor();
2294
2295 // bind the stream field values
2296 ctrMH = RecordSupport.bindCtrValues(ctrMH, desc, fieldValues);
2297
2298 try {
2299 return ctrMH.invoke();
2300 } catch (Exception e) {
2301 InvalidObjectException ioe = new InvalidObjectException(e.getMessage());
2302 ioe.initCause(e);
2303 throw ioe;
2304 } catch (Error e) {
2305 throw e;
2306 } catch (Throwable t) {
2307 ObjectStreamException ose = new InvalidObjectException(
2308 "ReflectiveOperationException during deserialization");
2309 ose.initCause(t);
2310 throw ose;
2311 }
2312 }
2313
2314 /**
2315 * Reads (or attempts to skip, if obj is null or is tagged with a
2316 * ClassNotFoundException) instance data for each serializable class of
2317 * object in stream, from superclass to subclass. Expects that passHandle
2318 * is set to obj's handle before this method is called.
2319 */
|
2165 if (cl == String.class || cl == Class.class
2166 || cl == ObjectStreamClass.class) {
2167 throw new InvalidClassException("invalid class descriptor");
2168 }
2169
2170 Object obj;
2171 try {
2172 obj = desc.isInstantiable() ? desc.newInstance() : null;
2173 } catch (Exception ex) {
2174 throw (IOException) new InvalidClassException(
2175 desc.forClass().getName(),
2176 "unable to create instance").initCause(ex);
2177 }
2178
2179 passHandle = handles.assign(unshared ? unsharedMarker : obj);
2180 ClassNotFoundException resolveEx = desc.getResolveException();
2181 if (resolveEx != null) {
2182 handles.markException(passHandle, resolveEx);
2183 }
2184
2185 final boolean isRecord = cl != null && isRecord(cl);
2186 if (isRecord) {
2187 assert obj == null;
2188 obj = readRecord(desc);
2189 if (!unshared)
2190 handles.setObject(passHandle, obj);
2191 } else if (desc.isExternalizable()) {
2192 readExternalData((Externalizable) obj, desc);
2193 } else {
2194 readSerialData(obj, desc);
2195 }
2196
2197 handles.finish(passHandle);
2198
2199 if (obj != null &&
2200 handles.lookupException(passHandle) == null &&
2201 desc.hasReadResolveMethod())
2202 {
2203 Object rep = desc.invokeReadResolve(obj);
2204 if (unshared && rep.getClass().isArray()) {
2205 rep = cloneArray(rep);
2272 * externalizable data remains in the stream, a subsequent read will
2273 * most likely throw a StreamCorruptedException.
2274 */
2275 }
2276
2277 /** Reads a record. */
2278 private Object readRecord(ObjectStreamClass desc) throws IOException {
2279 ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
2280 if (slots.length != 1) {
2281 // skip any superclass stream field values
2282 for (int i = 0; i < slots.length-1; i++) {
2283 ObjectStreamClass slotDesc = slots[i].desc;
2284 if (slots[i].hasData) {
2285 defaultReadFields(null, slotDesc);
2286 }
2287 }
2288 }
2289
2290 FieldValues fieldValues = defaultReadFields(null, desc);
2291
2292 // get canonical record constructor adapted to take two arguments:
2293 // - byte[] primValues
2294 // - Object[] objValues
2295 // and return Object
2296 MethodHandle ctrMH = RecordSupport.deserializationCtr(desc);
2297
2298 try {
2299 return (Object) ctrMH.invokeExact(fieldValues.primValues, fieldValues.objValues);
2300 } catch (Exception e) {
2301 InvalidObjectException ioe = new InvalidObjectException(e.getMessage());
2302 ioe.initCause(e);
2303 throw ioe;
2304 } catch (Error e) {
2305 throw e;
2306 } catch (Throwable t) {
2307 ObjectStreamException ose = new InvalidObjectException(
2308 "ReflectiveOperationException during deserialization");
2309 ose.initCause(t);
2310 throw ose;
2311 }
2312 }
2313
2314 /**
2315 * Reads (or attempts to skip, if obj is null or is tagged with a
2316 * ClassNotFoundException) instance data for each serializable class of
2317 * object in stream, from superclass to subclass. Expects that passHandle
2318 * is set to obj's handle before this method is called.
2319 */
|