summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2015-04-24 11:30:56 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-04-24 11:30:56 +0000
commit2b7e589a8ea095392e97d45f1feb04832bada21c (patch)
treec76e4a5261e61021d9be7c1465f9a7d0edd22add
parentdcc9e76ad6cb529666944c87ddac1a368724d259 (diff)
parentf5cd147674c1de0ef860ac28867358d8cfbcd958 (diff)
downloadlibcore-2b7e589a8ea095392e97d45f1feb04832bada21c.zip
libcore-2b7e589a8ea095392e97d45f1feb04832bada21c.tar.gz
libcore-2b7e589a8ea095392e97d45f1feb04832bada21c.tar.bz2
Merge "Tidy up Package and classloader comments"
-rw-r--r--libart/src/main/java/java/lang/ClassLoader.java4
-rw-r--r--luni/src/main/java/java/io/ObjectInputStream.java2
-rw-r--r--luni/src/main/java/java/lang/Package.java17
-rw-r--r--luni/src/test/java/libcore/java/lang/PackageTest.java7
-rw-r--r--luni/src/test/java/libcore/java/lang/TestPackageAnnotation.java26
-rw-r--r--luni/src/test/java/libcore/java/lang/package-info.java18
6 files changed, 57 insertions, 17 deletions
diff --git a/libart/src/main/java/java/lang/ClassLoader.java b/libart/src/main/java/java/lang/ClassLoader.java
index 9079dc4..dfbeeb5 100644
--- a/libart/src/main/java/java/lang/ClassLoader.java
+++ b/libart/src/main/java/java/lang/ClassLoader.java
@@ -646,8 +646,8 @@ public abstract class ClassLoader {
throw new IllegalArgumentException("Package " + name + " already defined");
}
- Package newPackage = new Package(name, specTitle, specVersion, specVendor, implTitle,
- implVersion, implVendor, sealBase);
+ Package newPackage = new Package(this, name, specTitle, specVersion, specVendor,
+ implTitle, implVersion, implVendor, sealBase);
packages.put(name, newPackage);
diff --git a/luni/src/main/java/java/io/ObjectInputStream.java b/luni/src/main/java/java/io/ObjectInputStream.java
index c588251..cd267b2 100644
--- a/luni/src/main/java/java/io/ObjectInputStream.java
+++ b/luni/src/main/java/java/io/ObjectInputStream.java
@@ -2255,8 +2255,6 @@ public class ObjectInputStream extends InputStream implements ObjectInput, Objec
if (cls == null) {
// not primitive class
- // Use the first non-null ClassLoader on the stack. If null, use
- // the system class loader
cls = Class.forName(className, false, callerClassLoader);
}
}
diff --git a/luni/src/main/java/java/lang/Package.java b/luni/src/main/java/java/lang/Package.java
index cff01b9..3c6c39c 100644
--- a/luni/src/main/java/java/lang/Package.java
+++ b/luni/src/main/java/java/lang/Package.java
@@ -51,6 +51,7 @@ import java.net.URL;
public class Package implements AnnotatedElement {
private static final Annotation[] NO_ANNOTATIONS = new Annotation[0];
+ private final ClassLoader classLoader;
private final String name;
private final String specTitle;
private final String specVersion;
@@ -60,8 +61,10 @@ public class Package implements AnnotatedElement {
private final String implVendor;
private final URL sealBase;
- Package(String name, String specTitle, String specVersion, String specVendor,
- String implTitle, String implVersion, String implVendor, URL sealBase) {
+ Package(ClassLoader classLoader, String name, String specTitle, String specVersion,
+ String specVendor, String implTitle, String implVersion, String implVendor,
+ URL sealBase) {
+ this.classLoader = classLoader;
this.name = name;
this.specTitle = specTitle;
this.specVersion = specVersion;
@@ -96,14 +99,8 @@ public class Package implements AnnotatedElement {
*/
public Annotation[] getAnnotations() {
try {
- 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);
+ Class<?> c = Class.forName(getName() + ".package-info", false /* initialize */,
+ classLoader);
return c.getAnnotations();
} catch (Exception ex) {
return NO_ANNOTATIONS;
diff --git a/luni/src/test/java/libcore/java/lang/PackageTest.java b/luni/src/test/java/libcore/java/lang/PackageTest.java
index 6e274a0..c004e23 100644
--- a/luni/src/test/java/libcore/java/lang/PackageTest.java
+++ b/luni/src/test/java/libcore/java/lang/PackageTest.java
@@ -25,9 +25,10 @@ public final class PackageTest extends TestCase {
private static final List<Package> packages = Arrays.asList(Package.getPackages());
public void test_getAnnotations() throws Exception {
- // Package annotations aren't supported, but pre-ICS we crashed.
- assertEquals(0, getClass().getPackage().getAnnotations().length);
- assertEquals(0, getClass().getPackage().getDeclaredAnnotations().length);
+ // Pre-ICS we crashed. To pass, the package-info and TestPackageAnnotation classes must be
+ // on the classpath.
+ assertEquals(1, getClass().getPackage().getAnnotations().length);
+ assertEquals(1, getClass().getPackage().getDeclaredAnnotations().length);
}
public void testGetPackage() {
diff --git a/luni/src/test/java/libcore/java/lang/TestPackageAnnotation.java b/luni/src/test/java/libcore/java/lang/TestPackageAnnotation.java
new file mode 100644
index 0000000..7626206
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/TestPackageAnnotation.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.lang;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+// Used by PackageTest
+@Target(ElementType.PACKAGE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TestPackageAnnotation {}
diff --git a/luni/src/test/java/libcore/java/lang/package-info.java b/luni/src/test/java/libcore/java/lang/package-info.java
new file mode 100644
index 0000000..d916e9a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/package-info.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+// Used by PackageTest
+@TestPackageAnnotation
+package libcore.java.lang; \ No newline at end of file