summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2015-04-20 22:00:28 -0700
committerBrian Carlstrom <bdc@google.com>2015-04-21 19:48:53 -0700
commit31ae6d22605a0967d722f935bc3a8b868ada4917 (patch)
treec52f58d7a6733df669c47be53f9fb7a5327f7d1f
parentd128a4cbeceef48b508ec076c536fb81f8a8b88f (diff)
downloadlibcore-31ae6d22605a0967d722f935bc3a8b868ada4917.zip
libcore-31ae6d22605a0967d722f935bc3a8b868ada4917.tar.gz
libcore-31ae6d22605a0967d722f935bc3a8b868ada4917.tar.bz2
Fix Class.forName(..., ..., null) to pass 068-classloader's testClassForName
This caused fallout elsewhere requiring - Package fix to pass 005-annotations - ObjectInputStream fix to pass 093-serialization Change-Id: I6bc470e20fa177e8a3debe55c90a84eef7ef518e
-rw-r--r--libart/src/main/java/dalvik/system/VMStack.java7
-rw-r--r--libart/src/main/java/java/lang/Class.java28
-rw-r--r--luni/src/main/java/java/io/ObjectInputStream.java5
-rw-r--r--luni/src/main/java/java/lang/Package.java25
4 files changed, 34 insertions, 31 deletions
diff --git a/libart/src/main/java/dalvik/system/VMStack.java b/libart/src/main/java/dalvik/system/VMStack.java
index ee0a0db..b69ab60 100644
--- a/libart/src/main/java/dalvik/system/VMStack.java
+++ b/libart/src/main/java/dalvik/system/VMStack.java
@@ -48,11 +48,10 @@ public final class VMStack {
native public static Class<?> getStackClass2();
/**
- * Returns the first ClassLoader on the call stack that isn't either of
- * the passed-in ClassLoaders.
+ * Returns the first ClassLoader on the call stack that isn't the
+ * bootstrap class loader.
*/
- public native static ClassLoader getClosestUserClassLoader(ClassLoader bootstrap,
- ClassLoader system);
+ public native static ClassLoader getClosestUserClassLoader();
/**
* Retrieves the stack trace from the specified thread.
diff --git a/libart/src/main/java/java/lang/Class.java b/libart/src/main/java/java/lang/Class.java
index d74fd14..1072ce8 100644
--- a/libart/src/main/java/java/lang/Class.java
+++ b/libart/src/main/java/java/lang/Class.java
@@ -292,7 +292,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* If the class has not yet been initialized and {@code shouldInitialize} is true,
* the class will be initialized.
*
- * <p>If the provided {@code classLoader} is null, the bootstrap
+ * <p>If the provided {@code classLoader} is {@code null}, the bootstrap
* class loader will be used to load the class.
*
* @throws ClassNotFoundException
@@ -307,7 +307,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
ClassLoader classLoader) throws ClassNotFoundException {
if (classLoader == null) {
- classLoader = ClassLoader.getSystemClassLoader();
+ classLoader = BootClassLoader.getInstance();
}
// Catch an Exception thrown by the underlying native code. It wraps
// up everything inside a ClassNotFoundException, even if e.g. an
@@ -527,8 +527,8 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
- * Returns the constructor with the given parameters if it is defined by this class; null
- * otherwise. This may return a non-public member.
+ * Returns the constructor with the given parameters if it is defined by this class;
+ * {@code null} otherwise. This may return a non-public member.
*
* @param args the types of the parameters to the constructor.
*/
@@ -645,7 +645,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
- * Returns the method if it is defined by this class; null otherwise. This may return a
+ * Returns the method if it is defined by this class; {@code null} otherwise. This may return a
* non-public member.
*
* @param name the method name
@@ -778,7 +778,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
public native Field[] getDeclaredFieldsUnchecked(boolean publicOnly);
/**
- * Returns the field if it is defined by this class; null otherwise. This
+ * Returns the field if it is defined by this class; {@code null} otherwise. This
* may return a non-public member.
*/
private native Field getDeclaredFieldInternal(String name);
@@ -1092,21 +1092,21 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
- * Returns the simple name of a member or local class, or null otherwise.
+ * Returns the simple name of a member or local class, or {@code null} otherwise.
*/
private String getInnerClassName() {
return AnnotationAccess.getInnerClassName(this);
}
/**
- * Returns null.
+ * Returns {@code null}.
*/
public ProtectionDomain getProtectionDomain() {
return null;
}
/**
- * Returns the URL of the given resource, or null if the resource is not found.
+ * Returns the URL of the given resource, or {@code null} if the resource is not found.
* The mapping between the resource name and the URL is managed by the class' class loader.
*
* @see ClassLoader
@@ -1137,8 +1137,8 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
- * Returns a read-only stream for the contents of the given resource, or null if the resource
- * is not found.
+ * Returns a read-only stream for the contents of the given resource, or {@code null} if the
+ * resource is not found.
* The mapping between the resource name and the stream is managed by the class' class loader.
*
* @see ClassLoader
@@ -1169,8 +1169,8 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
- * Returns null. (On Android, a {@code ClassLoader} can load classes from multiple dex files.
- * All classes from any given dex file will have the same signers, but different dex
+ * Returns {@code null}. (On Android, a {@code ClassLoader} can load classes from multiple dex
+ * files. All classes from any given dex file will have the same signers, but different dex
* files may have different signers. This does not fit well with the original
* {@code ClassLoader}-based model of {@code getSigners}.)
*/
@@ -1471,7 +1471,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
- * Returns the package name of this class. This returns null for classes in
+ * Returns the package name of this class. This returns {@code null} for classes in
* the default package.
*
* @hide
diff --git a/luni/src/main/java/java/io/ObjectInputStream.java b/luni/src/main/java/java/io/ObjectInputStream.java
index 3a89b52..c588251 100644
--- a/luni/src/main/java/java/io/ObjectInputStream.java
+++ b/luni/src/main/java/java/io/ObjectInputStream.java
@@ -1977,7 +1977,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput, Objec
// original/outside caller
if (++nestedLevels == 1) {
// Remember the caller's class loader
- callerClassLoader = VMStack.getClosestUserClassLoader(bootstrapLoader, systemLoader);
+ callerClassLoader = VMStack.getClosestUserClassLoader();
}
result = readNonPrimitiveContent(unshared);
@@ -2014,9 +2014,6 @@ public class ObjectInputStream extends InputStream implements ObjectInput, Objec
return result;
}
- private static final ClassLoader bootstrapLoader = Object.class.getClassLoader();
- private static final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
-
/**
* Method to be overridden by subclasses to read the next object from the
* source stream.
diff --git a/luni/src/main/java/java/lang/Package.java b/luni/src/main/java/java/lang/Package.java
index 7e30883..cff01b9 100644
--- a/luni/src/main/java/java/lang/Package.java
+++ b/luni/src/main/java/java/lang/Package.java
@@ -96,7 +96,14 @@ public class Package implements AnnotatedElement {
*/
public Annotation[] getAnnotations() {
try {
- Class<?> c = Class.forName(getName() + ".package-info");
+ ClassLoader classLoader = VMStack.getCallingClassLoader();
+ if (classLoader == null) {
+ classLoader = ClassLoader.getSystemClassLoader();
+ }
+ Class<?> c = Class.forName(getName() + ".package-info",
+ // TODO: It is unclear if we need to initialize here.
+ true,
+ classLoader);
return c.getAnnotations();
} catch (Exception ex) {
return NO_ANNOTATIONS;
@@ -175,11 +182,11 @@ public class Package implements AnnotatedElement {
* @see ClassLoader#getPackage(java.lang.String)
*/
public static Package getPackage(String packageName) {
- ClassLoader classloader = VMStack.getCallingClassLoader();
- if (classloader == null) {
- classloader = ClassLoader.getSystemClassLoader();
+ ClassLoader classLoader = VMStack.getCallingClassLoader();
+ if (classLoader == null) {
+ classLoader = ClassLoader.getSystemClassLoader();
}
- return classloader.getPackage(packageName);
+ return classLoader.getPackage(packageName);
}
/**
@@ -189,11 +196,11 @@ public class Package implements AnnotatedElement {
* @see ClassLoader#getPackages
*/
public static Package[] getPackages() {
- ClassLoader classloader = VMStack.getCallingClassLoader();
- if (classloader == null) {
- classloader = ClassLoader.getSystemClassLoader();
+ ClassLoader classLoader = VMStack.getCallingClassLoader();
+ if (classLoader == null) {
+ classLoader = ClassLoader.getSystemClassLoader();
}
- return classloader.getPackages();
+ return classLoader.getPackages();
}
/**