src/share/classes/java/io/ObjectOutputStream.java

Print this page

        

*** 1032,1042 **** * without violating security constraints: the subclass must not override * security-sensitive non-final methods, or else the * "enableSubclassImplementation" SerializablePermission is checked. */ private void verifySubclass() { ! Class cl = getClass(); if (cl == ObjectOutputStream.class) { return; } SecurityManager sm = System.getSecurityManager(); if (sm == null) { --- 1032,1042 ---- * without violating security constraints: the subclass must not override * security-sensitive non-final methods, or else the * "enableSubclassImplementation" SerializablePermission is checked. */ private void verifySubclass() { ! Class<?> cl = getClass(); if (cl == ObjectOutputStream.class) { return; } SecurityManager sm = System.getSecurityManager(); if (sm == null) {
*** 1058,1078 **** /** * Performs reflective checks on given subclass to verify that it doesn't * override security-sensitive non-final methods. Returns true if subclass * is "safe", false otherwise. */ ! private static boolean auditSubclass(final Class subcl) { Boolean result = AccessController.doPrivileged( new PrivilegedAction<Boolean>() { public Boolean run() { ! for (Class cl = subcl; cl != ObjectOutputStream.class; cl = cl.getSuperclass()) { try { cl.getDeclaredMethod( ! "writeUnshared", new Class[] { Object.class }); return Boolean.FALSE; } catch (NoSuchMethodException ex) { } try { cl.getDeclaredMethod("putFields", (Class[]) null); --- 1058,1078 ---- /** * Performs reflective checks on given subclass to verify that it doesn't * override security-sensitive non-final methods. Returns true if subclass * is "safe", false otherwise. */ ! private static boolean auditSubclass(final Class<?> subcl) { Boolean result = AccessController.doPrivileged( new PrivilegedAction<Boolean>() { public Boolean run() { ! for (Class<?> cl = subcl; cl != ObjectOutputStream.class; cl = cl.getSuperclass()) { try { cl.getDeclaredMethod( ! "writeUnshared", new Class<?>[] { Object.class }); return Boolean.FALSE; } catch (NoSuchMethodException ex) { } try { cl.getDeclaredMethod("putFields", (Class[]) null);
*** 1120,1134 **** return; } // check for replacement object Object orig = obj; ! Class cl = obj.getClass(); ObjectStreamClass desc; for (;;) { // REMIND: skip this check for strings/arrays? ! Class repCl; desc = ObjectStreamClass.lookup(cl, true); if (!desc.hasWriteReplaceMethod() || (obj = desc.invokeWriteReplace(obj)) == null || (repCl = obj.getClass()) == cl) { --- 1120,1134 ---- return; } // check for replacement object Object orig = obj; ! Class<?> cl = obj.getClass(); ObjectStreamClass desc; for (;;) { // REMIND: skip this check for strings/arrays? ! Class<?> repCl; desc = ObjectStreamClass.lookup(cl, true); if (!desc.hasWriteReplaceMethod() || (obj = desc.invokeWriteReplace(obj)) == null || (repCl = obj.getClass()) == cl) {
*** 1167,1177 **** if (obj instanceof String) { writeString((String) obj, unshared); } else if (cl.isArray()) { writeArray(obj, desc, unshared); } else if (obj instanceof Enum) { ! writeEnum((Enum) obj, desc, unshared); } else if (obj instanceof Serializable) { writeOrdinaryObject(obj, desc, unshared); } else { if (extendedDebugInfo) { throw new NotSerializableException( --- 1167,1177 ---- if (obj instanceof String) { writeString((String) obj, unshared); } else if (cl.isArray()) { writeArray(obj, desc, unshared); } else if (obj instanceof Enum) { ! writeEnum((Enum<?>) obj, desc, unshared); } else if (obj instanceof Serializable) { writeOrdinaryObject(obj, desc, unshared); } else { if (extendedDebugInfo) { throw new NotSerializableException(
*** 1202,1212 **** } /** * Writes representation of given class to stream. */ ! private void writeClass(Class cl, boolean unshared) throws IOException { bout.writeByte(TC_CLASS); writeClassDesc(ObjectStreamClass.lookup(cl, true), false); handles.assign(unshared ? null : cl); } --- 1202,1212 ---- } /** * Writes representation of given class to stream. */ ! private void writeClass(Class<?> cl, boolean unshared) throws IOException { bout.writeByte(TC_CLASS); writeClassDesc(ObjectStreamClass.lookup(cl, true), false); handles.assign(unshared ? null : cl); }
*** 1235,1245 **** throws IOException { bout.writeByte(TC_PROXYCLASSDESC); handles.assign(unshared ? null : desc); ! Class cl = desc.forClass(); Class[] ifaces = cl.getInterfaces(); bout.writeInt(ifaces.length); for (int i = 0; i < ifaces.length; i++) { bout.writeUTF(ifaces[i].getName()); } --- 1235,1245 ---- throws IOException { bout.writeByte(TC_PROXYCLASSDESC); handles.assign(unshared ? null : desc); ! Class<?> cl = desc.forClass(); Class[] ifaces = cl.getInterfaces(); bout.writeInt(ifaces.length); for (int i = 0; i < ifaces.length; i++) { bout.writeUTF(ifaces[i].getName()); }
*** 1267,1277 **** desc.writeNonProxy(this); } else { writeClassDescriptor(desc); } ! Class cl = desc.forClass(); bout.setBlockDataMode(true); annotateClass(cl); bout.setBlockDataMode(false); bout.writeByte(TC_ENDBLOCKDATA); --- 1267,1277 ---- desc.writeNonProxy(this); } else { writeClassDescriptor(desc); } ! Class<?> cl = desc.forClass(); bout.setBlockDataMode(true); annotateClass(cl); bout.setBlockDataMode(false); bout.writeByte(TC_ENDBLOCKDATA);
*** 1304,1314 **** { bout.writeByte(TC_ARRAY); writeClassDesc(desc, false); handles.assign(unshared ? null : array); ! Class ccl = desc.forClass().getComponentType(); if (ccl.isPrimitive()) { if (ccl == Integer.TYPE) { int[] ia = (int[]) array; bout.writeInt(ia.length); bout.writeInts(ia, 0, ia.length); --- 1304,1314 ---- { bout.writeByte(TC_ARRAY); writeClassDesc(desc, false); handles.assign(unshared ? null : array); ! Class<?> ccl = desc.forClass().getComponentType(); if (ccl.isPrimitive()) { if (ccl == Integer.TYPE) { int[] ia = (int[]) array; bout.writeInt(ia.length); bout.writeInts(ia, 0, ia.length);
*** 1375,1385 **** } /** * Writes given enum constant to stream. */ ! private void writeEnum(Enum en, ObjectStreamClass desc, boolean unshared) throws IOException { bout.writeByte(TC_ENUM); --- 1375,1385 ---- } /** * Writes given enum constant to stream. */ ! private void writeEnum(Enum<?> en, ObjectStreamClass desc, boolean unshared) throws IOException { bout.writeByte(TC_ENUM);
*** 1698,1708 **** * Returns offset of field with given name and type. A specified type * of null matches all types, Object.class matches all non-primitive * types, and any other non-null type matches assignable types only. * Throws IllegalArgumentException if no matching field found. */ ! private int getFieldOffset(String name, Class type) { ObjectStreamField field = desc.getField(name, type); if (field == null) { throw new IllegalArgumentException("no such field " + name + " with type " + type); } --- 1698,1708 ---- * Returns offset of field with given name and type. A specified type * of null matches all types, Object.class matches all non-primitive * types, and any other non-null type matches assignable types only. * Throws IllegalArgumentException if no matching field found. */ ! private int getFieldOffset(String name, Class<?> type) { ObjectStreamField field = desc.getField(name, type); if (field == null) { throw new IllegalArgumentException("no such field " + name + " with type " + type); }