1.1 --- a/emul/compact/src/main/java/java/io/ObjectOutputStream.java Mon Jan 28 18:12:47 2013 +0100
1.2 +++ b/emul/compact/src/main/java/java/io/ObjectOutputStream.java Mon Jan 28 18:15:21 2013 +0100
1.3 @@ -25,17 +25,10 @@
1.4
1.5 package java.io;
1.6
1.7 -import java.io.ObjectStreamClass.WeakClassKey;
1.8 -import java.lang.ref.ReferenceQueue;
1.9 -import java.security.AccessController;
1.10 -import java.security.PrivilegedAction;
1.11 import java.util.ArrayList;
1.12 import java.util.Arrays;
1.13 import java.util.List;
1.14 -import java.util.concurrent.ConcurrentHashMap;
1.15 -import java.util.concurrent.ConcurrentMap;
1.16 -import static java.io.ObjectStreamClass.processQueue;
1.17 -import java.io.SerialCallbackContext;
1.18 +import org.apidesign.bck2brwsr.emul.lang.System;
1.19
1.20 /**
1.21 * An ObjectOutputStream writes primitive data types and graphs of Java objects
1.22 @@ -161,17 +154,6 @@
1.23 public class ObjectOutputStream
1.24 extends OutputStream implements ObjectOutput, ObjectStreamConstants
1.25 {
1.26 -
1.27 - private static class Caches {
1.28 - /** cache of subclass security audit results */
1.29 - static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
1.30 - new ConcurrentHashMap<>();
1.31 -
1.32 - /** queue for WeakReferences to audited subclasses */
1.33 - static final ReferenceQueue<Class<?>> subclassAuditsQueue =
1.34 - new ReferenceQueue<>();
1.35 - }
1.36 -
1.37 /** filter stream for handling block data conversion */
1.38 private final BlockDataOutputStream bout;
1.39 /** obj -> wire handle map */
1.40 @@ -197,7 +179,7 @@
1.41 * object currently being serialized and descriptor for current class.
1.42 * Null when not during writeObject upcall.
1.43 */
1.44 - private SerialCallbackContext curContext;
1.45 + private Object curContext;
1.46 /** current PutField object */
1.47 private PutFieldImpl curPut;
1.48
1.49 @@ -208,10 +190,7 @@
1.50 * value of "sun.io.serialization.extendedDebugInfo" property,
1.51 * as true or false for extended information about exception's place
1.52 */
1.53 - private static final boolean extendedDebugInfo =
1.54 - java.security.AccessController.doPrivileged(
1.55 - new sun.security.action.GetBooleanAction(
1.56 - "sun.io.serialization.extendedDebugInfo")).booleanValue();
1.57 + private static final boolean extendedDebugInfo = false;
1.58
1.59 /**
1.60 * Creates an ObjectOutputStream that writes to the specified OutputStream.
1.61 @@ -268,15 +247,7 @@
1.62 * @see java.io.SerializablePermission
1.63 */
1.64 protected ObjectOutputStream() throws IOException, SecurityException {
1.65 - SecurityManager sm = System.getSecurityManager();
1.66 - if (sm != null) {
1.67 - sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
1.68 - }
1.69 - bout = null;
1.70 - handles = null;
1.71 - subs = null;
1.72 - enableOverride = true;
1.73 - debugInfoStack = null;
1.74 + throw new SecurityException();
1.75 }
1.76
1.77 /**
1.78 @@ -432,8 +403,8 @@
1.79 if ( curContext == null ) {
1.80 throw new NotActiveException("not in call to writeObject");
1.81 }
1.82 - Object curObj = curContext.getObj();
1.83 - ObjectStreamClass curDesc = curContext.getDesc();
1.84 + Object curObj = null; // curContext.getObj();
1.85 + ObjectStreamClass curDesc = null; // curContext.getDesc();
1.86 bout.setBlockDataMode(false);
1.87 defaultWriteFields(curObj, curDesc);
1.88 bout.setBlockDataMode(true);
1.89 @@ -454,8 +425,8 @@
1.90 if (curContext == null) {
1.91 throw new NotActiveException("not in call to writeObject");
1.92 }
1.93 - Object curObj = curContext.getObj();
1.94 - ObjectStreamClass curDesc = curContext.getDesc();
1.95 + Object curObj = null; // curContext.getObj();
1.96 + ObjectStreamClass curDesc = null; // curContext.getDesc();
1.97 curPut = new PutFieldImpl(curDesc);
1.98 }
1.99 return curPut;
1.100 @@ -607,17 +578,7 @@
1.101 protected boolean enableReplaceObject(boolean enable)
1.102 throws SecurityException
1.103 {
1.104 - if (enable == enableReplace) {
1.105 - return enable;
1.106 - }
1.107 - if (enable) {
1.108 - SecurityManager sm = System.getSecurityManager();
1.109 - if (sm != null) {
1.110 - sm.checkPermission(SUBSTITUTION_PERMISSION);
1.111 - }
1.112 - }
1.113 - enableReplace = enable;
1.114 - return !enableReplace;
1.115 + throw new SecurityException();
1.116 }
1.117
1.118 /**
1.119 @@ -1038,53 +999,7 @@
1.120 if (cl == ObjectOutputStream.class) {
1.121 return;
1.122 }
1.123 - SecurityManager sm = System.getSecurityManager();
1.124 - if (sm == null) {
1.125 - return;
1.126 - }
1.127 - processQueue(Caches.subclassAuditsQueue, Caches.subclassAudits);
1.128 - WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue);
1.129 - Boolean result = Caches.subclassAudits.get(key);
1.130 - if (result == null) {
1.131 - result = Boolean.valueOf(auditSubclass(cl));
1.132 - Caches.subclassAudits.putIfAbsent(key, result);
1.133 - }
1.134 - if (result.booleanValue()) {
1.135 - return;
1.136 - }
1.137 - sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
1.138 - }
1.139 -
1.140 - /**
1.141 - * Performs reflective checks on given subclass to verify that it doesn't
1.142 - * override security-sensitive non-final methods. Returns true if subclass
1.143 - * is "safe", false otherwise.
1.144 - */
1.145 - private static boolean auditSubclass(final Class subcl) {
1.146 - Boolean result = AccessController.doPrivileged(
1.147 - new PrivilegedAction<Boolean>() {
1.148 - public Boolean run() {
1.149 - for (Class cl = subcl;
1.150 - cl != ObjectOutputStream.class;
1.151 - cl = cl.getSuperclass())
1.152 - {
1.153 - try {
1.154 - cl.getDeclaredMethod(
1.155 - "writeUnshared", new Class[] { Object.class });
1.156 - return Boolean.FALSE;
1.157 - } catch (NoSuchMethodException ex) {
1.158 - }
1.159 - try {
1.160 - cl.getDeclaredMethod("putFields", (Class[]) null);
1.161 - return Boolean.FALSE;
1.162 - } catch (NoSuchMethodException ex) {
1.163 - }
1.164 - }
1.165 - return Boolean.TRUE;
1.166 - }
1.167 - }
1.168 - );
1.169 - return result.booleanValue();
1.170 + throw new SecurityException();
1.171 }
1.172
1.173 /**
1.174 @@ -1433,7 +1348,7 @@
1.175 if (extendedDebugInfo) {
1.176 debugInfoStack.push("writeExternal data");
1.177 }
1.178 - SerialCallbackContext oldContext = curContext;
1.179 + Object oldContext = curContext;
1.180 try {
1.181 curContext = null;
1.182 if (protocol == PROTOCOL_VERSION_1) {
1.183 @@ -1467,7 +1382,7 @@
1.184 if (slotDesc.hasWriteObjectMethod()) {
1.185 PutFieldImpl oldPut = curPut;
1.186 curPut = null;
1.187 - SerialCallbackContext oldContext = curContext;
1.188 + Object oldContext = curContext;
1.189
1.190 if (extendedDebugInfo) {
1.191 debugInfoStack.push(
1.192 @@ -1475,13 +1390,13 @@
1.193 slotDesc.getName() + "\")");
1.194 }
1.195 try {
1.196 - curContext = new SerialCallbackContext(obj, slotDesc);
1.197 + curContext = new Object(); //new SerialCallbackContext(obj, slotDesc);
1.198 bout.setBlockDataMode(true);
1.199 slotDesc.invokeWriteObject(obj, this);
1.200 bout.setBlockDataMode(false);
1.201 bout.writeByte(TC_ENDBLOCKDATA);
1.202 } finally {
1.203 - curContext.setUsed();
1.204 + //curContext.setUsed();
1.205 curContext = oldContext;
1.206 if (extendedDebugInfo) {
1.207 debugInfoStack.pop();