diff options
author | Neil Fuller <nfuller@google.com> | 2015-04-22 11:39:49 +0100 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2015-04-22 16:42:37 +0100 |
commit | f5cd147674c1de0ef860ac28867358d8cfbcd958 (patch) | |
tree | 1d0a176e88e6808d8170c9806a29456369ec7e5e | |
parent | 298bf64cb09d9e11f99aeda8a7a0a1f709ec91f9 (diff) | |
download | libcore-f5cd147674c1de0ef860ac28867358d8cfbcd958.zip libcore-f5cd147674c1de0ef860ac28867358d8cfbcd958.tar.gz libcore-f5cd147674c1de0ef860ac28867358d8cfbcd958.tar.bz2 |
Tidy up Package and classloader comments
After commit 31ae6d22605a0967d722f935bc3a8b868ada4917
Remove a TODO, improve a test and fix a comment.
Also fixes a bug in Package demonstrated by the improved test.
Bug: 20482259
Change-Id: I6b37413d7004ce85c99bb854e0ec41e5f8588250
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 |