summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dalvik/src/main/java/dalvik/system/VMStack.java16
-rw-r--r--luni/src/main/java/java/io/ObjectInputStream.java19
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.
*