< prev index next >

src/java.base/share/classes/java/io/ObjectInputStream.java

Print this page

        

*** 374,383 **** --- 374,385 ---- vlist = null; serialFilter = ObjectInputFilter.Config.getSerialFilter(); enableOverride = true; } + private ClassLoader cachedLoader = null; + /** * 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 overridden using the writeObject
*** 415,424 **** --- 417,434 ---- { if (enableOverride) { return readObjectOverride(); } + ClassLoader prevClassLoader = null; + boolean cached = false; + if (curContext == null) { + prevClassLoader = cachedLoader; + cachedLoader = latestUserDefinedLoader(); + cached = true; + } + // if nested read, passHandle contains handle of enclosing object int outerHandle = passHandle; try { Object obj = readObject0(false); handles.markDependency(outerHandle, passHandle);
*** 431,440 **** --- 441,453 ---- freeze(); } return obj; } finally { passHandle = outerHandle; + if (cached) { + cachedLoader = prevClassLoader; + } if (closed && depth == 0) { clear(); } } }
*** 510,519 **** --- 523,539 ---- * @throws OptionalDataException if primitive data is next in stream * @throws IOException if an I/O error occurs during deserialization * @since 1.4 */ public Object readUnshared() throws IOException, ClassNotFoundException { + ClassLoader prevClassLoader = null; + boolean cached = false; + if (curContext == null) { + prevClassLoader = cachedLoader; + cachedLoader = latestUserDefinedLoader(); + cached = true; + } // if nested read, passHandle contains handle of enclosing object int outerHandle = passHandle; try { Object obj = readObject0(true); handles.markDependency(outerHandle, passHandle);
*** 526,535 **** --- 546,558 ---- freeze(); } return obj; } finally { passHandle = outerHandle; + if (cached) { + cachedLoader = prevClassLoader; + } if (closed && depth == 0) { clear(); } } }
*** 681,690 **** --- 704,716 ---- protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { String name = desc.getName(); try { + if (cachedLoader != null) + return Class.forName(name, false, cachedLoader); + else return Class.forName(name, false, latestUserDefinedLoader()); } catch (ClassNotFoundException ex) { Class<?> cl = primClasses.get(name); if (cl != null) { return cl;
< prev index next >