private Serializable handleIndirection() { int indirection = read_long() + get_offset() - 4; if (valueCache != null && valueCache.containsVal(indirection)) { java.io.Serializable cachedValue = (java.io.Serializable)valueCache.getKey(indirection); return cachedValue; } else { // In RMI-IIOP the ValueHandler will recognize this // exception and use the provided indirection value // to lookup a possible indirection to an object // currently on the deserialization stack. throw new IndirectionException(indirection); } }
/** * Override the actions of the final method "readObject()" * in ObjectInputStream. * @since JDK1.1.6 * * Read an object from the ObjectInputStream. * The class of the object, the signature of the class, and the values * of the non-transient and non-static fields of the class and all * of its supertypes are read. Default deserializing for a class can be * overriden using the writeObject and readObject methods. * Objects referenced by this object are read transitively so * that a complete equivalent graph of objects is reconstructed by readObject. <p> * * The root object is completly restored when all of its fields * and the objects it references are completely restored. At this * point the object validation callbacks are executed in order * based on their registered priorities. The callbacks are * registered by objects (in the readObject special methods) * as they are individually restored. * * Exceptions are thrown for problems with the InputStream and for classes * that should not be deserialized. All exceptions are fatal to the * InputStream and leave it in an indeterminate state; it is up to the caller * to ignore or recover the stream state. * @exception java.lang.ClassNotFoundException Class of a serialized object * cannot be found. * @exception InvalidClassException Something is wrong with a class used by * serialization. * @exception StreamCorruptedException Control information in the * stream is inconsistent. * @exception OptionalDataException Primitive data was found in the * stream instead of objects. * @exception IOException Any of the usual Input/Output related exceptions. * @since JDK1.1 */ public final synchronized Object readObjectDelegate() throws IOException { try { readObjectState.readData(this); return orbStream.read_abstract_interface(); } catch (MARSHAL marshalException) { handleOptionalDataMarshalException(marshalException, true); throw marshalException; } catch(IndirectionException cdrie) { // The CDR stream had never seen the given offset before, // so check the recursion manager (it will throw an // IOException if it doesn't have a reference, either). return activeRecursionMgr.getObject(cdrie.offset); } }
private final void inputRemoteMembersForReadFields(java.util.Map fieldToValueMap) throws InvalidClassException, StreamCorruptedException, ClassNotFoundException, IOException { // Must have this local variable since defaultReadObjectFVDMembers // may get mangled by recursion. ValueMember fields[] = defaultReadObjectFVDMembers; try { for (int i = 0; i < fields.length; i++) { switch (fields[i].type.kind().value()) { case TCKind._tk_octet: byte byteValue = orbStream.read_octet(); fieldToValueMap.put(fields[i].name, new Byte(byteValue)); break; case TCKind._tk_boolean: boolean booleanValue = orbStream.read_boolean(); fieldToValueMap.put(fields[i].name, new Boolean(booleanValue)); break; case TCKind._tk_char: // Backwards compatibility. Older Sun ORBs sent // _tk_char even though they read and wrote wchars // correctly. // // Fall through to the _tk_wchar case. case TCKind._tk_wchar: char charValue = orbStream.read_wchar(); fieldToValueMap.put(fields[i].name, new Character(charValue)); break; case TCKind._tk_short: short shortValue = orbStream.read_short(); fieldToValueMap.put(fields[i].name, new Short(shortValue)); break; case TCKind._tk_long: int intValue = orbStream.read_long(); fieldToValueMap.put(fields[i].name, new Integer(intValue)); break; case TCKind._tk_longlong: long longValue = orbStream.read_longlong(); fieldToValueMap.put(fields[i].name, new Long(longValue)); break; case TCKind._tk_float: float floatValue = orbStream.read_float(); fieldToValueMap.put(fields[i].name, new Float(floatValue)); break; case TCKind._tk_double: double doubleValue = orbStream.read_double(); fieldToValueMap.put(fields[i].name, new Double(doubleValue)); break; case TCKind._tk_value: case TCKind._tk_objref: case TCKind._tk_value_box: Object objectValue = null; try { objectValue = inputObjectField(fields[i], cbSender); } catch (IndirectionException cdrie) { // The CDR stream had never seen the given offset before, // so check the recursion manager (it will throw an // IOException if it doesn't have a reference, either). objectValue = activeRecursionMgr.getObject(cdrie.offset); } fieldToValueMap.put(fields[i].name, objectValue); break; default: // XXX I18N, logging needed. throw new StreamCorruptedException("Unknown kind: " + fields[i].type.kind().value()); } } } catch (Throwable t) { StreamCorruptedException result = new StreamCorruptedException(t.getMessage()); result.initCause(t); throw result; } }
private void inputClassFields(Object o, Class cl, ObjectStreamField[] fields, com.sun.org.omg.SendingContext.CodeBase sender) throws InvalidClassException, StreamCorruptedException, ClassNotFoundException, IOException { int primFields = fields.length - currentClassDesc.objFields; if (o != null) { for (int i = 0; i < primFields; ++i) { if (fields[i].getField() == null) continue; inputPrimitiveField(o, cl, fields[i]); } } /* Read and set object fields from the input stream. */ if (currentClassDesc.objFields > 0) { for (int i = primFields; i < fields.length; i++) { Object objectValue = null; try { objectValue = inputObjectField(fields[i]); } catch(IndirectionException cdrie) { // The CDR stream had never seen the given offset before, // so check the recursion manager (it will throw an // IOException if it doesn't have a reference, either). objectValue = activeRecursionMgr.getObject(cdrie.offset); } if ((o == null) || (fields[i].getField() == null)) { continue; } try { Class fieldCl = fields[i].getClazz(); if (objectValue != null && !fieldCl.isInstance(objectValue)) { throw new IllegalArgumentException(); } bridge.putObject( o, fields[i].getFieldID(), objectValue ) ; // reflective code: fields[i].getField().set( o, objectValue ) ; } catch (IllegalArgumentException e) { ClassCastException exc = new ClassCastException("Assigning instance of class " + objectValue.getClass().getName() + " to field " + currentClassDesc.getName() + '#' + fields[i].getField().getName()); exc.initCause( e ) ; throw exc ; } } // end : for loop } }
private void inputClassFields(Object o, Class cl, ObjectStreamField[] fields, com.sun.org.omg.SendingContext.CodeBase sender) throws InvalidClassException, StreamCorruptedException, ClassNotFoundException, IOException { int primFields = fields.length - currentClassDesc.objFields; if (o != null) { for (int i = 0; i < primFields; ++i) { inputPrimitiveField(o, cl, fields[i]); } } /* Read and set object fields from the input stream. */ if (currentClassDesc.objFields > 0) { for (int i = primFields; i < fields.length; i++) { Object objectValue = null; try { objectValue = inputObjectField(fields[i]); } catch(IndirectionException cdrie) { // The CDR stream had never seen the given offset before, // so check the recursion manager (it will throw an // IOException if it doesn't have a reference, either). objectValue = activeRecursionMgr.getObject(cdrie.offset); } if ((o == null) || (fields[i].getField() == null)) { continue; } try { Class fieldCl = fields[i].getClazz(); if ((objectValue != null) && (!fieldCl.isAssignableFrom( objectValue.getClass()))) { throw new IllegalArgumentException("Field mismatch"); } Field classField = null; try { classField = cl.getDeclaredField(fields[i].getName()); } catch (NoSuchFieldException nsfEx) { throw new IllegalArgumentException(nsfEx); } catch (SecurityException secEx) { throw new IllegalArgumentException(secEx.getCause()); } Class<?> declaredFieldClass = classField.getType(); // check input field type is a declared field type // input field is a subclass of the declared field if (!declaredFieldClass.isAssignableFrom(fieldCl)) { throw new IllegalArgumentException( "Field Type mismatch"); } if (objectValue != null && !fieldCl.isInstance(objectValue)) { throw new IllegalArgumentException(); } bridge.putObject( o, fields[i].getFieldID(), objectValue ) ; // reflective code: fields[i].getField().set( o, objectValue ) ; } catch (IllegalArgumentException e) { ClassCastException exc = new ClassCastException("Assigning instance of class " + objectValue.getClass().getName() + " to field " + currentClassDesc.getName() + '#' + fields[i].getField().getName()); exc.initCause( e ) ; throw exc ; } } // end : for loop } }
/** * Override the actions of the final method "readObject()" * in ObjectInputStream. * @since JDK1.1.6 * * Read an object from the ObjectInputStream. * The class of the object, the signature of the class, and the values * of the non-transient and non-static fields of the class and all * of its supertypes are read. Default deserializing for a class can be * overriden using the writeObject and readObject methods. * Objects referenced by this object are read transitively so * that a complete equivalent graph of objects is reconstructed by readObject. <p> * * The root object is completly restored when all of its fields * and the objects it references are completely restored. At this * point the object validation callbacks are executed in order * based on their registered priorities. The callbacks are * registered by objects (in the readObject special methods) * as they are individually restored. * * Exceptions are thrown for problems with the InputStream and for classes * that should not be deserialized. All exceptions are fatal to the * InputStream and leave it in an indeterminate state; it is up to the caller * to ignore or recover the stream state. * @exception java.lang.ClassNotFoundException Class of a serialized object * cannot be found. * @exception InvalidClassException Something is wrong with a class used by * serialization. * @exception StreamCorruptedException Control information in the * stream is inconsistent. * @exception OptionalDataException Primitive data was found in the * stream instead of objects. * @exception IOException Any of the usual Input/Output related exceptions. * @since JDK1.1 */ public final Object readObjectDelegate() throws IOException { try { readObjectState.readData(this); return orbStream.read_abstract_interface(); } catch (MARSHAL marshalException) { handleOptionalDataMarshalException(marshalException, true); throw marshalException; } catch(IndirectionException cdrie) { // The CDR stream had never seen the given offset before, // so check the recursion manager (it will throw an // IOException if it doesn't have a reference, either). return activeRecursionMgr.getObject(cdrie.offset); } }
private void inputClassFields(Object o, Class cl, ObjectStreamField[] fields, com.sun.org.omg.SendingContext.CodeBase sender) throws InvalidClassException, StreamCorruptedException, ClassNotFoundException, IOException { int primFields = fields.length - currentClassDesc.objFields; if (o != null) { for (int i = 0; i < primFields; ++i) { if (fields[i].getField() == null) continue; inputPrimitiveField(o, cl, fields[i]); } } /* Read and set object fields from the input stream. */ if (currentClassDesc.objFields > 0) { for (int i = primFields; i < fields.length; i++) { Object objectValue = null; try { objectValue = inputObjectField(fields[i]); } catch(IndirectionException cdrie) { // The CDR stream had never seen the given offset before, // so check the recursion manager (it will throw an // IOException if it doesn't have a reference, either). objectValue = activeRecursionMgr.getObject(cdrie.offset); } if ((o == null) || (fields[i].getField() == null)) { continue; } try { bridge.putObject( o, fields[i].getFieldID(), objectValue ) ; // reflective code: fields[i].getField().set( o, objectValue ) ; } catch (IllegalArgumentException e) { ClassCastException exc = new ClassCastException("Assigning instance of class " + objectValue.getClass().getName() + " to field " + currentClassDesc.getName() + '#' + fields[i].getField().getName()); exc.initCause( e ) ; throw exc ; } } // end : for loop } }