diff options
author | Elliott Hughes <enh@google.com> | 2011-09-20 12:08:34 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-06-05 14:05:25 -0700 |
commit | 552f220a1c5f481293bf47b21726635a0e5df601 (patch) | |
tree | 16c2be76d563904f48c7578df2beb967adf0e6f9 | |
parent | 940f85738c2f1326317458f11f8d6b9880adfe42 (diff) | |
download | libcore-552f220a1c5f481293bf47b21726635a0e5df601.zip libcore-552f220a1c5f481293bf47b21726635a0e5df601.tar.gz libcore-552f220a1c5f481293bf47b21726635a0e5df601.tar.bz2 |
Change the VMStack interface used by serialization.
(cherry picked from commit 8b44bdb6063816eeb90da6b4f8aa3ed9f38fe140)
Change-Id: I5da041caa3037a4093f05dec4e03aed4f466a21d
-rw-r--r-- | dalvik/src/main/java/dalvik/system/VMStack.java | 16 | ||||
-rw-r--r-- | luni/src/main/java/java/io/ObjectInputStream.java | 19 |
2 files changed, 17 insertions, 18 deletions
diff --git a/dalvik/src/main/java/dalvik/system/VMStack.java b/dalvik/src/main/java/dalvik/system/VMStack.java index 9a2be23..bae1829 100644 --- a/dalvik/src/main/java/dalvik/system/VMStack.java +++ b/dalvik/src/main/java/dalvik/system/VMStack.java @@ -59,6 +59,22 @@ public final class VMStack { native public static Class<?>[] getClasses(int maxDepth); /** + * Returns the first ClassLoader on the call stack that isn't either of + * the passed-in ClassLoaders. + */ + public static ClassLoader getClosestUserClassLoader(ClassLoader bootstrap, + ClassLoader system) { + Class<?>[] stackClasses = VMStack.getClasses(-1); + for (Class<?> stackClass : stackClasses) { + ClassLoader loader = stackClass.getClassLoader(); + if (loader != null && loader != bootstrap && loader != system) { + return loader; + } + } + return null; + } + + /** * Retrieves the stack trace from the specified thread. * * @param t diff --git a/luni/src/main/java/java/io/ObjectInputStream.java b/luni/src/main/java/java/io/ObjectInputStream.java index 0476901..0b15161 100644 --- a/luni/src/main/java/java/io/ObjectInputStream.java +++ b/luni/src/main/java/java/io/ObjectInputStream.java @@ -2000,7 +2000,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput, Objec // original/outside caller if (++nestedLevels == 1) { // Remember the caller's class loader - callerClassLoader = getClosestUserClassLoader(); + callerClassLoader = VMStack.getClosestUserClassLoader(bootstrapLoader, systemLoader); } result = readNonPrimitiveContent(unshared); @@ -2041,23 +2041,6 @@ public class ObjectInputStream extends InputStream implements ObjectInput, Objec private static final ClassLoader systemLoader = ClassLoader.getSystemClassLoader(); /** - * Searches up the call stack to find the closest user-defined class loader. - * - * @return a user-defined class loader or null if one isn't found - */ - private static ClassLoader getClosestUserClassLoader() { - Class<?>[] stackClasses = VMStack.getClasses(-1); - for (Class<?> stackClass : stackClasses) { - ClassLoader loader = stackClass.getClassLoader(); - if (loader != null && loader != bootstrapLoader - && loader != systemLoader) { - return loader; - } - } - return null; - } - - /** * Method to be overridden by subclasses to read the next object from the * source stream. * |