1.1 --- a/emul/src/main/java/java/io/ObjectStreamField.java Sat Sep 29 08:26:30 2012 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,314 +0,0 @@
1.4 -/*
1.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 - *
1.8 - * This code is free software; you can redistribute it and/or modify it
1.9 - * under the terms of the GNU General Public License version 2 only, as
1.10 - * published by the Free Software Foundation. Oracle designates this
1.11 - * particular file as subject to the "Classpath" exception as provided
1.12 - * by Oracle in the LICENSE file that accompanied this code.
1.13 - *
1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 - * version 2 for more details (a copy is included in the LICENSE file that
1.18 - * accompanied this code).
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License version
1.21 - * 2 along with this work; if not, write to the Free Software Foundation,
1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 - *
1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 - * or visit www.oracle.com if you need additional information or have any
1.26 - * questions.
1.27 - */
1.28 -
1.29 -package java.io;
1.30 -
1.31 -import java.lang.reflect.Field;
1.32 -
1.33 -/**
1.34 - * A description of a Serializable field from a Serializable class. An array
1.35 - * of ObjectStreamFields is used to declare the Serializable fields of a class.
1.36 - *
1.37 - * @author Mike Warres
1.38 - * @author Roger Riggs
1.39 - * @see ObjectStreamClass
1.40 - * @since 1.2
1.41 - */
1.42 -public class ObjectStreamField
1.43 - implements Comparable<Object>
1.44 -{
1.45 -
1.46 - /** field name */
1.47 - private final String name;
1.48 - /** canonical JVM signature of field type */
1.49 - private final String signature;
1.50 - /** field type (Object.class if unknown non-primitive type) */
1.51 - private final Class<?> type;
1.52 - /** whether or not to (de)serialize field values as unshared */
1.53 - private final boolean unshared;
1.54 - /** corresponding reflective field object, if any */
1.55 - private final Field field;
1.56 - /** offset of field value in enclosing field group */
1.57 - private int offset = 0;
1.58 -
1.59 - /**
1.60 - * Create a Serializable field with the specified type. This field should
1.61 - * be documented with a <code>serialField</code> tag.
1.62 - *
1.63 - * @param name the name of the serializable field
1.64 - * @param type the <code>Class</code> object of the serializable field
1.65 - */
1.66 - public ObjectStreamField(String name, Class<?> type) {
1.67 - this(name, type, false);
1.68 - }
1.69 -
1.70 - /**
1.71 - * Creates an ObjectStreamField representing a serializable field with the
1.72 - * given name and type. If unshared is false, values of the represented
1.73 - * field are serialized and deserialized in the default manner--if the
1.74 - * field is non-primitive, object values are serialized and deserialized as
1.75 - * if they had been written and read by calls to writeObject and
1.76 - * readObject. If unshared is true, values of the represented field are
1.77 - * serialized and deserialized as if they had been written and read by
1.78 - * calls to writeUnshared and readUnshared.
1.79 - *
1.80 - * @param name field name
1.81 - * @param type field type
1.82 - * @param unshared if false, write/read field values in the same manner
1.83 - * as writeObject/readObject; if true, write/read in the same
1.84 - * manner as writeUnshared/readUnshared
1.85 - * @since 1.4
1.86 - */
1.87 - public ObjectStreamField(String name, Class<?> type, boolean unshared) {
1.88 - if (name == null) {
1.89 - throw new NullPointerException();
1.90 - }
1.91 - this.name = name;
1.92 - this.type = type;
1.93 - this.unshared = unshared;
1.94 - signature = getClassSignature(type).intern();
1.95 - field = null;
1.96 - }
1.97 -
1.98 - /**
1.99 - * Creates an ObjectStreamField representing a field with the given name,
1.100 - * signature and unshared setting.
1.101 - */
1.102 - ObjectStreamField(String name, String signature, boolean unshared) {
1.103 - if (name == null) {
1.104 - throw new NullPointerException();
1.105 - }
1.106 - this.name = name;
1.107 - this.signature = signature.intern();
1.108 - this.unshared = unshared;
1.109 - field = null;
1.110 -
1.111 - switch (signature.charAt(0)) {
1.112 - case 'Z': type = Boolean.TYPE; break;
1.113 - case 'B': type = Byte.TYPE; break;
1.114 - case 'C': type = Character.TYPE; break;
1.115 - case 'S': type = Short.TYPE; break;
1.116 - case 'I': type = Integer.TYPE; break;
1.117 - case 'J': type = Long.TYPE; break;
1.118 - case 'F': type = Float.TYPE; break;
1.119 - case 'D': type = Double.TYPE; break;
1.120 - case 'L':
1.121 - case '[': type = Object.class; break;
1.122 - default: throw new IllegalArgumentException("illegal signature");
1.123 - }
1.124 - }
1.125 -
1.126 - /**
1.127 - * Creates an ObjectStreamField representing the given field with the
1.128 - * specified unshared setting. For compatibility with the behavior of
1.129 - * earlier serialization implementations, a "showType" parameter is
1.130 - * necessary to govern whether or not a getType() call on this
1.131 - * ObjectStreamField (if non-primitive) will return Object.class (as
1.132 - * opposed to a more specific reference type).
1.133 - */
1.134 - ObjectStreamField(Field field, boolean unshared, boolean showType) {
1.135 - this.field = field;
1.136 - this.unshared = unshared;
1.137 - name = field.getName();
1.138 - Class<?> ftype = field.getType();
1.139 - type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
1.140 - signature = getClassSignature(ftype).intern();
1.141 - }
1.142 -
1.143 - /**
1.144 - * Get the name of this field.
1.145 - *
1.146 - * @return a <code>String</code> representing the name of the serializable
1.147 - * field
1.148 - */
1.149 - public String getName() {
1.150 - return name;
1.151 - }
1.152 -
1.153 - /**
1.154 - * Get the type of the field. If the type is non-primitive and this
1.155 - * <code>ObjectStreamField</code> was obtained from a deserialized {@link
1.156 - * ObjectStreamClass} instance, then <code>Object.class</code> is returned.
1.157 - * Otherwise, the <code>Class</code> object for the type of the field is
1.158 - * returned.
1.159 - *
1.160 - * @return a <code>Class</code> object representing the type of the
1.161 - * serializable field
1.162 - */
1.163 - public Class<?> getType() {
1.164 - return type;
1.165 - }
1.166 -
1.167 - /**
1.168 - * Returns character encoding of field type. The encoding is as follows:
1.169 - * <blockquote><pre>
1.170 - * B byte
1.171 - * C char
1.172 - * D double
1.173 - * F float
1.174 - * I int
1.175 - * J long
1.176 - * L class or interface
1.177 - * S short
1.178 - * Z boolean
1.179 - * [ array
1.180 - * </pre></blockquote>
1.181 - *
1.182 - * @return the typecode of the serializable field
1.183 - */
1.184 - // REMIND: deprecate?
1.185 - public char getTypeCode() {
1.186 - return signature.charAt(0);
1.187 - }
1.188 -
1.189 - /**
1.190 - * Return the JVM type signature.
1.191 - *
1.192 - * @return null if this field has a primitive type.
1.193 - */
1.194 - // REMIND: deprecate?
1.195 - public String getTypeString() {
1.196 - return isPrimitive() ? null : signature;
1.197 - }
1.198 -
1.199 - /**
1.200 - * Offset of field within instance data.
1.201 - *
1.202 - * @return the offset of this field
1.203 - * @see #setOffset
1.204 - */
1.205 - // REMIND: deprecate?
1.206 - public int getOffset() {
1.207 - return offset;
1.208 - }
1.209 -
1.210 - /**
1.211 - * Offset within instance data.
1.212 - *
1.213 - * @param offset the offset of the field
1.214 - * @see #getOffset
1.215 - */
1.216 - // REMIND: deprecate?
1.217 - protected void setOffset(int offset) {
1.218 - this.offset = offset;
1.219 - }
1.220 -
1.221 - /**
1.222 - * Return true if this field has a primitive type.
1.223 - *
1.224 - * @return true if and only if this field corresponds to a primitive type
1.225 - */
1.226 - // REMIND: deprecate?
1.227 - public boolean isPrimitive() {
1.228 - char tcode = signature.charAt(0);
1.229 - return ((tcode != 'L') && (tcode != '['));
1.230 - }
1.231 -
1.232 - /**
1.233 - * Returns boolean value indicating whether or not the serializable field
1.234 - * represented by this ObjectStreamField instance is unshared.
1.235 - *
1.236 - * @since 1.4
1.237 - */
1.238 - public boolean isUnshared() {
1.239 - return unshared;
1.240 - }
1.241 -
1.242 - /**
1.243 - * Compare this field with another <code>ObjectStreamField</code>. Return
1.244 - * -1 if this is smaller, 0 if equal, 1 if greater. Types that are
1.245 - * primitives are "smaller" than object types. If equal, the field names
1.246 - * are compared.
1.247 - */
1.248 - // REMIND: deprecate?
1.249 - public int compareTo(Object obj) {
1.250 - ObjectStreamField other = (ObjectStreamField) obj;
1.251 - boolean isPrim = isPrimitive();
1.252 - if (isPrim != other.isPrimitive()) {
1.253 - return isPrim ? -1 : 1;
1.254 - }
1.255 - return name.compareTo(other.name);
1.256 - }
1.257 -
1.258 - /**
1.259 - * Return a string that describes this field.
1.260 - */
1.261 - public String toString() {
1.262 - return signature + ' ' + name;
1.263 - }
1.264 -
1.265 - /**
1.266 - * Returns field represented by this ObjectStreamField, or null if
1.267 - * ObjectStreamField is not associated with an actual field.
1.268 - */
1.269 - Field getField() {
1.270 - return field;
1.271 - }
1.272 -
1.273 - /**
1.274 - * Returns JVM type signature of field (similar to getTypeString, except
1.275 - * that signature strings are returned for primitive fields as well).
1.276 - */
1.277 - String getSignature() {
1.278 - return signature;
1.279 - }
1.280 -
1.281 - /**
1.282 - * Returns JVM type signature for given class.
1.283 - */
1.284 - private static String getClassSignature(Class<?> cl) {
1.285 - StringBuilder sbuf = new StringBuilder();
1.286 - while (cl.isArray()) {
1.287 - sbuf.append('[');
1.288 - cl = cl.getComponentType();
1.289 - }
1.290 - if (cl.isPrimitive()) {
1.291 - if (cl == Integer.TYPE) {
1.292 - sbuf.append('I');
1.293 - } else if (cl == Byte.TYPE) {
1.294 - sbuf.append('B');
1.295 - } else if (cl == Long.TYPE) {
1.296 - sbuf.append('J');
1.297 - } else if (cl == Float.TYPE) {
1.298 - sbuf.append('F');
1.299 - } else if (cl == Double.TYPE) {
1.300 - sbuf.append('D');
1.301 - } else if (cl == Short.TYPE) {
1.302 - sbuf.append('S');
1.303 - } else if (cl == Character.TYPE) {
1.304 - sbuf.append('C');
1.305 - } else if (cl == Boolean.TYPE) {
1.306 - sbuf.append('Z');
1.307 - } else if (cl == Void.TYPE) {
1.308 - sbuf.append('V');
1.309 - } else {
1.310 - throw new InternalError();
1.311 - }
1.312 - } else {
1.313 - sbuf.append('L' + cl.getName().replace('.', '/') + ';');
1.314 - }
1.315 - return sbuf.toString();
1.316 - }
1.317 -}
2.1 --- a/emul/src/main/java/java/lang/Class.java Sat Sep 29 08:26:30 2012 +0200
2.2 +++ b/emul/src/main/java/java/lang/Class.java Sat Sep 29 10:47:42 2012 +0200
2.3 @@ -25,47 +25,7 @@
2.4
2.5 package java.lang;
2.6
2.7 -import java.lang.reflect.Array;
2.8 -import java.lang.reflect.GenericArrayType;
2.9 -import java.lang.reflect.Member;
2.10 -import java.lang.reflect.Field;
2.11 -import java.lang.reflect.Method;
2.12 -import java.lang.reflect.Constructor;
2.13 -import java.lang.reflect.GenericDeclaration;
2.14 -import java.lang.reflect.Modifier;
2.15 -import java.lang.reflect.Type;
2.16 -import java.lang.reflect.TypeVariable;
2.17 -import java.lang.reflect.InvocationTargetException;
2.18 -import java.lang.ref.SoftReference;
2.19 -import java.io.InputStream;
2.20 -import java.io.ObjectStreamField;
2.21 -import java.security.AccessController;
2.22 -import java.security.PrivilegedAction;
2.23 -import java.util.ArrayList;
2.24 -import java.util.Arrays;
2.25 -import java.util.Collection;
2.26 -import java.util.HashSet;
2.27 -import java.util.Iterator;
2.28 -import java.util.List;
2.29 -import java.util.LinkedList;
2.30 -import java.util.LinkedHashSet;
2.31 -import java.util.Set;
2.32 -import java.util.Map;
2.33 -import java.util.HashMap;
2.34 -import sun.misc.Unsafe;
2.35 -import sun.reflect.ConstantPool;
2.36 -import sun.reflect.Reflection;
2.37 -import sun.reflect.ReflectionFactory;
2.38 -import sun.reflect.SignatureIterator;
2.39 -import sun.reflect.generics.factory.CoreReflectionFactory;
2.40 -import sun.reflect.generics.factory.GenericsFactory;
2.41 -import sun.reflect.generics.repository.ClassRepository;
2.42 -import sun.reflect.generics.repository.MethodRepository;
2.43 -import sun.reflect.generics.repository.ConstructorRepository;
2.44 -import sun.reflect.generics.scope.ClassScope;
2.45 -import sun.security.util.SecurityConstants;
2.46 import java.lang.annotation.Annotation;
2.47 -import sun.reflect.annotation.*;
2.48
2.49 /**
2.50 * Instances of the class {@code Class} represent classes and
2.51 @@ -113,19 +73,14 @@
2.52 * @since JDK1.0
2.53 */
2.54 public final
2.55 - class Class<T> implements java.io.Serializable,
2.56 - java.lang.reflect.GenericDeclaration,
2.57 - java.lang.reflect.Type,
2.58 - java.lang.reflect.AnnotatedElement {
2.59 + class Class<T> implements java.io.Serializable {
2.60 +// java.lang.reflect.GenericDeclaration,
2.61 +// java.lang.reflect.Type,
2.62 +// java.lang.reflect.AnnotatedElement {
2.63 private static final int ANNOTATION= 0x00002000;
2.64 private static final int ENUM = 0x00004000;
2.65 private static final int SYNTHETIC = 0x00001000;
2.66
2.67 - private static native void registerNatives();
2.68 - static {
2.69 - registerNatives();
2.70 - }
2.71 -
2.72 /*
2.73 * Constructor. Only the Java Virtual Machine creates Class
2.74 * objects.
2.75 @@ -183,93 +138,11 @@
2.76 */
2.77 public static Class<?> forName(String className)
2.78 throws ClassNotFoundException {
2.79 - return forName0(className, true, ClassLoader.getCallerClassLoader());
2.80 + throw new UnsupportedOperationException();
2.81 }
2.82
2.83
2.84 /**
2.85 - * Returns the {@code Class} object associated with the class or
2.86 - * interface with the given string name, using the given class loader.
2.87 - * Given the fully qualified name for a class or interface (in the same
2.88 - * format returned by {@code getName}) this method attempts to
2.89 - * locate, load, and link the class or interface. The specified class
2.90 - * loader is used to load the class or interface. If the parameter
2.91 - * {@code loader} is null, the class is loaded through the bootstrap
2.92 - * class loader. The class is initialized only if the
2.93 - * {@code initialize} parameter is {@code true} and if it has
2.94 - * not been initialized earlier.
2.95 - *
2.96 - * <p> If {@code name} denotes a primitive type or void, an attempt
2.97 - * will be made to locate a user-defined class in the unnamed package whose
2.98 - * name is {@code name}. Therefore, this method cannot be used to
2.99 - * obtain any of the {@code Class} objects representing primitive
2.100 - * types or void.
2.101 - *
2.102 - * <p> If {@code name} denotes an array class, the component type of
2.103 - * the array class is loaded but not initialized.
2.104 - *
2.105 - * <p> For example, in an instance method the expression:
2.106 - *
2.107 - * <blockquote>
2.108 - * {@code Class.forName("Foo")}
2.109 - * </blockquote>
2.110 - *
2.111 - * is equivalent to:
2.112 - *
2.113 - * <blockquote>
2.114 - * {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
2.115 - * </blockquote>
2.116 - *
2.117 - * Note that this method throws errors related to loading, linking or
2.118 - * initializing as specified in Sections 12.2, 12.3 and 12.4 of <em>The
2.119 - * Java Language Specification</em>.
2.120 - * Note that this method does not check whether the requested class
2.121 - * is accessible to its caller.
2.122 - *
2.123 - * <p> If the {@code loader} is {@code null}, and a security
2.124 - * manager is present, and the caller's class loader is not null, then this
2.125 - * method calls the security manager's {@code checkPermission} method
2.126 - * with a {@code RuntimePermission("getClassLoader")} permission to
2.127 - * ensure it's ok to access the bootstrap class loader.
2.128 - *
2.129 - * @param name fully qualified name of the desired class
2.130 - * @param initialize whether the class must be initialized
2.131 - * @param loader class loader from which the class must be loaded
2.132 - * @return class object representing the desired class
2.133 - *
2.134 - * @exception LinkageError if the linkage fails
2.135 - * @exception ExceptionInInitializerError if the initialization provoked
2.136 - * by this method fails
2.137 - * @exception ClassNotFoundException if the class cannot be located by
2.138 - * the specified class loader
2.139 - *
2.140 - * @see java.lang.Class#forName(String)
2.141 - * @see java.lang.ClassLoader
2.142 - * @since 1.2
2.143 - */
2.144 - public static Class<?> forName(String name, boolean initialize,
2.145 - ClassLoader loader)
2.146 - throws ClassNotFoundException
2.147 - {
2.148 - if (loader == null) {
2.149 - SecurityManager sm = System.getSecurityManager();
2.150 - if (sm != null) {
2.151 - ClassLoader ccl = ClassLoader.getCallerClassLoader();
2.152 - if (ccl != null) {
2.153 - sm.checkPermission(
2.154 - SecurityConstants.GET_CLASSLOADER_PERMISSION);
2.155 - }
2.156 - }
2.157 - }
2.158 - return forName0(name, initialize, loader);
2.159 - }
2.160 -
2.161 - /** Called after security checks have been made. */
2.162 - private static native Class<?> forName0(String name, boolean initialize,
2.163 - ClassLoader loader)
2.164 - throws ClassNotFoundException;
2.165 -
2.166 - /**
2.167 * Creates a new instance of the class represented by this {@code Class}
2.168 * object. The class is instantiated as if by a {@code new}
2.169 * expression with an empty argument list. The class is initialized if it
2.170 @@ -319,67 +192,9 @@
2.171 public T newInstance()
2.172 throws InstantiationException, IllegalAccessException
2.173 {
2.174 - if (System.getSecurityManager() != null) {
2.175 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.176 - }
2.177 - return newInstance0();
2.178 + throw new UnsupportedOperationException("Should be somehow supported");
2.179 }
2.180
2.181 - private T newInstance0()
2.182 - throws InstantiationException, IllegalAccessException
2.183 - {
2.184 - // NOTE: the following code may not be strictly correct under
2.185 - // the current Java memory model.
2.186 -
2.187 - // Constructor lookup
2.188 - if (cachedConstructor == null) {
2.189 - if (this == Class.class) {
2.190 - throw new IllegalAccessException(
2.191 - "Can not call newInstance() on the Class for java.lang.Class"
2.192 - );
2.193 - }
2.194 - try {
2.195 - Class<?>[] empty = {};
2.196 - final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
2.197 - // Disable accessibility checks on the constructor
2.198 - // since we have to do the security check here anyway
2.199 - // (the stack depth is wrong for the Constructor's
2.200 - // security check to work)
2.201 - java.security.AccessController.doPrivileged(
2.202 - new java.security.PrivilegedAction<Void>() {
2.203 - public Void run() {
2.204 - c.setAccessible(true);
2.205 - return null;
2.206 - }
2.207 - });
2.208 - cachedConstructor = c;
2.209 - } catch (NoSuchMethodException e) {
2.210 - throw new InstantiationException(getName());
2.211 - }
2.212 - }
2.213 - Constructor<T> tmpConstructor = cachedConstructor;
2.214 - // Security check (same as in java.lang.reflect.Constructor)
2.215 - int modifiers = tmpConstructor.getModifiers();
2.216 - if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
2.217 - Class<?> caller = Reflection.getCallerClass(3);
2.218 - if (newInstanceCallerCache != caller) {
2.219 - Reflection.ensureMemberAccess(caller, this, null, modifiers);
2.220 - newInstanceCallerCache = caller;
2.221 - }
2.222 - }
2.223 - // Run constructor
2.224 - try {
2.225 - return tmpConstructor.newInstance((Object[])null);
2.226 - } catch (InvocationTargetException e) {
2.227 - Unsafe.getUnsafe().throwException(e.getTargetException());
2.228 - // Not reached
2.229 - return null;
2.230 - }
2.231 - }
2.232 - private volatile transient Constructor<T> cachedConstructor;
2.233 - private volatile transient Class<?> newInstanceCallerCache;
2.234 -
2.235 -
2.236 /**
2.237 * Determines if the specified {@code Object} is assignment-compatible
2.238 * with the object represented by this {@code Class}. This method is
2.239 @@ -566,83 +381,13 @@
2.240 * represented by this object.
2.241 */
2.242 public String getName() {
2.243 - String name = this.name;
2.244 - if (name == null)
2.245 - this.name = name = getName0();
2.246 - return name;
2.247 + throw new UnsupportedOperationException();
2.248 +// String name = this.name;
2.249 +// if (name == null)
2.250 +// this.name = name = getName0();
2.251 +// return name;
2.252 }
2.253
2.254 - // cache the name to reduce the number of calls into the VM
2.255 - private transient String name;
2.256 - private native String getName0();
2.257 -
2.258 - /**
2.259 - * Returns the class loader for the class. Some implementations may use
2.260 - * null to represent the bootstrap class loader. This method will return
2.261 - * null in such implementations if this class was loaded by the bootstrap
2.262 - * class loader.
2.263 - *
2.264 - * <p> If a security manager is present, and the caller's class loader is
2.265 - * not null and the caller's class loader is not the same as or an ancestor of
2.266 - * the class loader for the class whose class loader is requested, then
2.267 - * this method calls the security manager's {@code checkPermission}
2.268 - * method with a {@code RuntimePermission("getClassLoader")}
2.269 - * permission to ensure it's ok to access the class loader for the class.
2.270 - *
2.271 - * <p>If this object
2.272 - * represents a primitive type or void, null is returned.
2.273 - *
2.274 - * @return the class loader that loaded the class or interface
2.275 - * represented by this object.
2.276 - * @throws SecurityException
2.277 - * if a security manager exists and its
2.278 - * {@code checkPermission} method denies
2.279 - * access to the class loader for the class.
2.280 - * @see java.lang.ClassLoader
2.281 - * @see SecurityManager#checkPermission
2.282 - * @see java.lang.RuntimePermission
2.283 - */
2.284 - public ClassLoader getClassLoader() {
2.285 - ClassLoader cl = getClassLoader0();
2.286 - if (cl == null)
2.287 - return null;
2.288 - SecurityManager sm = System.getSecurityManager();
2.289 - if (sm != null) {
2.290 - ClassLoader ccl = ClassLoader.getCallerClassLoader();
2.291 - if (ccl != null && ccl != cl && !cl.isAncestor(ccl)) {
2.292 - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
2.293 - }
2.294 - }
2.295 - return cl;
2.296 - }
2.297 -
2.298 - // Package-private to allow ClassLoader access
2.299 - native ClassLoader getClassLoader0();
2.300 -
2.301 -
2.302 - /**
2.303 - * Returns an array of {@code TypeVariable} objects that represent the
2.304 - * type variables declared by the generic declaration represented by this
2.305 - * {@code GenericDeclaration} object, in declaration order. Returns an
2.306 - * array of length 0 if the underlying generic declaration declares no type
2.307 - * variables.
2.308 - *
2.309 - * @return an array of {@code TypeVariable} objects that represent
2.310 - * the type variables declared by this generic declaration
2.311 - * @throws java.lang.reflect.GenericSignatureFormatError if the generic
2.312 - * signature of this generic declaration does not conform to
2.313 - * the format specified in
2.314 - * <cite>The Java™ Virtual Machine Specification</cite>
2.315 - * @since 1.5
2.316 - */
2.317 - public TypeVariable<Class<T>>[] getTypeParameters() {
2.318 - if (getGenericSignature() != null)
2.319 - return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
2.320 - else
2.321 - return (TypeVariable<Class<T>>[])new TypeVariable<?>[0];
2.322 - }
2.323 -
2.324 -
2.325 /**
2.326 * Returns the {@code Class} representing the superclass of the entity
2.327 * (class, interface, primitive type or void) represented by this
2.328 @@ -656,180 +401,6 @@
2.329 */
2.330 public native Class<? super T> getSuperclass();
2.331
2.332 -
2.333 - /**
2.334 - * Returns the {@code Type} representing the direct superclass of
2.335 - * the entity (class, interface, primitive type or void) represented by
2.336 - * this {@code Class}.
2.337 - *
2.338 - * <p>If the superclass is a parameterized type, the {@code Type}
2.339 - * object returned must accurately reflect the actual type
2.340 - * parameters used in the source code. The parameterized type
2.341 - * representing the superclass is created if it had not been
2.342 - * created before. See the declaration of {@link
2.343 - * java.lang.reflect.ParameterizedType ParameterizedType} for the
2.344 - * semantics of the creation process for parameterized types. If
2.345 - * this {@code Class} represents either the {@code Object}
2.346 - * class, an interface, a primitive type, or void, then null is
2.347 - * returned. If this object represents an array class then the
2.348 - * {@code Class} object representing the {@code Object} class is
2.349 - * returned.
2.350 - *
2.351 - * @throws java.lang.reflect.GenericSignatureFormatError if the generic
2.352 - * class signature does not conform to the format specified in
2.353 - * <cite>The Java™ Virtual Machine Specification</cite>
2.354 - * @throws TypeNotPresentException if the generic superclass
2.355 - * refers to a non-existent type declaration
2.356 - * @throws java.lang.reflect.MalformedParameterizedTypeException if the
2.357 - * generic superclass refers to a parameterized type that cannot be
2.358 - * instantiated for any reason
2.359 - * @return the superclass of the class represented by this object
2.360 - * @since 1.5
2.361 - */
2.362 - public Type getGenericSuperclass() {
2.363 - if (getGenericSignature() != null) {
2.364 - // Historical irregularity:
2.365 - // Generic signature marks interfaces with superclass = Object
2.366 - // but this API returns null for interfaces
2.367 - if (isInterface())
2.368 - return null;
2.369 - return getGenericInfo().getSuperclass();
2.370 - } else
2.371 - return getSuperclass();
2.372 - }
2.373 -
2.374 - /**
2.375 - * Gets the package for this class. The class loader of this class is used
2.376 - * to find the package. If the class was loaded by the bootstrap class
2.377 - * loader the set of packages loaded from CLASSPATH is searched to find the
2.378 - * package of the class. Null is returned if no package object was created
2.379 - * by the class loader of this class.
2.380 - *
2.381 - * <p> Packages have attributes for versions and specifications only if the
2.382 - * information was defined in the manifests that accompany the classes, and
2.383 - * if the class loader created the package instance with the attributes
2.384 - * from the manifest.
2.385 - *
2.386 - * @return the package of the class, or null if no package
2.387 - * information is available from the archive or codebase.
2.388 - */
2.389 - public Package getPackage() {
2.390 - return Package.getPackage(this);
2.391 - }
2.392 -
2.393 -
2.394 - /**
2.395 - * Determines the interfaces implemented by the class or interface
2.396 - * represented by this object.
2.397 - *
2.398 - * <p> If this object represents a class, the return value is an array
2.399 - * containing objects representing all interfaces implemented by the
2.400 - * class. The order of the interface objects in the array corresponds to
2.401 - * the order of the interface names in the {@code implements} clause
2.402 - * of the declaration of the class represented by this object. For
2.403 - * example, given the declaration:
2.404 - * <blockquote>
2.405 - * {@code class Shimmer implements FloorWax, DessertTopping { ... }}
2.406 - * </blockquote>
2.407 - * suppose the value of {@code s} is an instance of
2.408 - * {@code Shimmer}; the value of the expression:
2.409 - * <blockquote>
2.410 - * {@code s.getClass().getInterfaces()[0]}
2.411 - * </blockquote>
2.412 - * is the {@code Class} object that represents interface
2.413 - * {@code FloorWax}; and the value of:
2.414 - * <blockquote>
2.415 - * {@code s.getClass().getInterfaces()[1]}
2.416 - * </blockquote>
2.417 - * is the {@code Class} object that represents interface
2.418 - * {@code DessertTopping}.
2.419 - *
2.420 - * <p> If this object represents an interface, the array contains objects
2.421 - * representing all interfaces extended by the interface. The order of the
2.422 - * interface objects in the array corresponds to the order of the interface
2.423 - * names in the {@code extends} clause of the declaration of the
2.424 - * interface represented by this object.
2.425 - *
2.426 - * <p> If this object represents a class or interface that implements no
2.427 - * interfaces, the method returns an array of length 0.
2.428 - *
2.429 - * <p> If this object represents a primitive type or void, the method
2.430 - * returns an array of length 0.
2.431 - *
2.432 - * @return an array of interfaces implemented by this class.
2.433 - */
2.434 - public native Class<?>[] getInterfaces();
2.435 -
2.436 - /**
2.437 - * Returns the {@code Type}s representing the interfaces
2.438 - * directly implemented by the class or interface represented by
2.439 - * this object.
2.440 - *
2.441 - * <p>If a superinterface is a parameterized type, the
2.442 - * {@code Type} object returned for it must accurately reflect
2.443 - * the actual type parameters used in the source code. The
2.444 - * parameterized type representing each superinterface is created
2.445 - * if it had not been created before. See the declaration of
2.446 - * {@link java.lang.reflect.ParameterizedType ParameterizedType}
2.447 - * for the semantics of the creation process for parameterized
2.448 - * types.
2.449 - *
2.450 - * <p> If this object represents a class, the return value is an
2.451 - * array containing objects representing all interfaces
2.452 - * implemented by the class. The order of the interface objects in
2.453 - * the array corresponds to the order of the interface names in
2.454 - * the {@code implements} clause of the declaration of the class
2.455 - * represented by this object. In the case of an array class, the
2.456 - * interfaces {@code Cloneable} and {@code Serializable} are
2.457 - * returned in that order.
2.458 - *
2.459 - * <p>If this object represents an interface, the array contains
2.460 - * objects representing all interfaces directly extended by the
2.461 - * interface. The order of the interface objects in the array
2.462 - * corresponds to the order of the interface names in the
2.463 - * {@code extends} clause of the declaration of the interface
2.464 - * represented by this object.
2.465 - *
2.466 - * <p>If this object represents a class or interface that
2.467 - * implements no interfaces, the method returns an array of length
2.468 - * 0.
2.469 - *
2.470 - * <p>If this object represents a primitive type or void, the
2.471 - * method returns an array of length 0.
2.472 - *
2.473 - * @throws java.lang.reflect.GenericSignatureFormatError
2.474 - * if the generic class signature does not conform to the format
2.475 - * specified in
2.476 - * <cite>The Java™ Virtual Machine Specification</cite>
2.477 - * @throws TypeNotPresentException if any of the generic
2.478 - * superinterfaces refers to a non-existent type declaration
2.479 - * @throws java.lang.reflect.MalformedParameterizedTypeException
2.480 - * if any of the generic superinterfaces refer to a parameterized
2.481 - * type that cannot be instantiated for any reason
2.482 - * @return an array of interfaces implemented by this class
2.483 - * @since 1.5
2.484 - */
2.485 - public Type[] getGenericInterfaces() {
2.486 - if (getGenericSignature() != null)
2.487 - return getGenericInfo().getSuperInterfaces();
2.488 - else
2.489 - return getInterfaces();
2.490 - }
2.491 -
2.492 -
2.493 - /**
2.494 - * Returns the {@code Class} representing the component type of an
2.495 - * array. If this class does not represent an array class this method
2.496 - * returns null.
2.497 - *
2.498 - * @return the {@code Class} representing the component type of this
2.499 - * class if this class is an array
2.500 - * @see java.lang.reflect.Array
2.501 - * @since JDK1.1
2.502 - */
2.503 - public native Class<?> getComponentType();
2.504 -
2.505 -
2.506 /**
2.507 * Returns the Java language modifiers for this class or interface, encoded
2.508 * in an integer. The modifiers consist of the Java Virtual Machine's
2.509 @@ -861,259 +432,6 @@
2.510
2.511
2.512 /**
2.513 - * Gets the signers of this class.
2.514 - *
2.515 - * @return the signers of this class, or null if there are no signers. In
2.516 - * particular, this method returns null if this object represents
2.517 - * a primitive type or void.
2.518 - * @since JDK1.1
2.519 - */
2.520 - public native Object[] getSigners();
2.521 -
2.522 -
2.523 - /**
2.524 - * Set the signers of this class.
2.525 - */
2.526 - native void setSigners(Object[] signers);
2.527 -
2.528 -
2.529 - /**
2.530 - * If this {@code Class} object represents a local or anonymous
2.531 - * class within a method, returns a {@link
2.532 - * java.lang.reflect.Method Method} object representing the
2.533 - * immediately enclosing method of the underlying class. Returns
2.534 - * {@code null} otherwise.
2.535 - *
2.536 - * In particular, this method returns {@code null} if the underlying
2.537 - * class is a local or anonymous class immediately enclosed by a type
2.538 - * declaration, instance initializer or static initializer.
2.539 - *
2.540 - * @return the immediately enclosing method of the underlying class, if
2.541 - * that class is a local or anonymous class; otherwise {@code null}.
2.542 - * @since 1.5
2.543 - */
2.544 - public Method getEnclosingMethod() {
2.545 - EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
2.546 -
2.547 - if (enclosingInfo == null)
2.548 - return null;
2.549 - else {
2.550 - if (!enclosingInfo.isMethod())
2.551 - return null;
2.552 -
2.553 - MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
2.554 - getFactory());
2.555 - Class<?> returnType = toClass(typeInfo.getReturnType());
2.556 - Type [] parameterTypes = typeInfo.getParameterTypes();
2.557 - Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];
2.558 -
2.559 - // Convert Types to Classes; returned types *should*
2.560 - // be class objects since the methodDescriptor's used
2.561 - // don't have generics information
2.562 - for(int i = 0; i < parameterClasses.length; i++)
2.563 - parameterClasses[i] = toClass(parameterTypes[i]);
2.564 -
2.565 - /*
2.566 - * Loop over all declared methods; match method name,
2.567 - * number of and type of parameters, *and* return
2.568 - * type. Matching return type is also necessary
2.569 - * because of covariant returns, etc.
2.570 - */
2.571 - for(Method m: enclosingInfo.getEnclosingClass().getDeclaredMethods()) {
2.572 - if (m.getName().equals(enclosingInfo.getName()) ) {
2.573 - Class<?>[] candidateParamClasses = m.getParameterTypes();
2.574 - if (candidateParamClasses.length == parameterClasses.length) {
2.575 - boolean matches = true;
2.576 - for(int i = 0; i < candidateParamClasses.length; i++) {
2.577 - if (!candidateParamClasses[i].equals(parameterClasses[i])) {
2.578 - matches = false;
2.579 - break;
2.580 - }
2.581 - }
2.582 -
2.583 - if (matches) { // finally, check return type
2.584 - if (m.getReturnType().equals(returnType) )
2.585 - return m;
2.586 - }
2.587 - }
2.588 - }
2.589 - }
2.590 -
2.591 - throw new InternalError("Enclosing method not found");
2.592 - }
2.593 - }
2.594 -
2.595 - private native Object[] getEnclosingMethod0();
2.596 -
2.597 - private EnclosingMethodInfo getEnclosingMethodInfo() {
2.598 - Object[] enclosingInfo = getEnclosingMethod0();
2.599 - if (enclosingInfo == null)
2.600 - return null;
2.601 - else {
2.602 - return new EnclosingMethodInfo(enclosingInfo);
2.603 - }
2.604 - }
2.605 -
2.606 - private final static class EnclosingMethodInfo {
2.607 - private Class<?> enclosingClass;
2.608 - private String name;
2.609 - private String descriptor;
2.610 -
2.611 - private EnclosingMethodInfo(Object[] enclosingInfo) {
2.612 - if (enclosingInfo.length != 3)
2.613 - throw new InternalError("Malformed enclosing method information");
2.614 - try {
2.615 - // The array is expected to have three elements:
2.616 -
2.617 - // the immediately enclosing class
2.618 - enclosingClass = (Class<?>) enclosingInfo[0];
2.619 - assert(enclosingClass != null);
2.620 -
2.621 - // the immediately enclosing method or constructor's
2.622 - // name (can be null).
2.623 - name = (String) enclosingInfo[1];
2.624 -
2.625 - // the immediately enclosing method or constructor's
2.626 - // descriptor (null iff name is).
2.627 - descriptor = (String) enclosingInfo[2];
2.628 - assert((name != null && descriptor != null) || name == descriptor);
2.629 - } catch (ClassCastException cce) {
2.630 - throw new InternalError("Invalid type in enclosing method information");
2.631 - }
2.632 - }
2.633 -
2.634 - boolean isPartial() {
2.635 - return enclosingClass == null || name == null || descriptor == null;
2.636 - }
2.637 -
2.638 - boolean isConstructor() { return !isPartial() && "<init>".equals(name); }
2.639 -
2.640 - boolean isMethod() { return !isPartial() && !isConstructor() && !"<clinit>".equals(name); }
2.641 -
2.642 - Class<?> getEnclosingClass() { return enclosingClass; }
2.643 -
2.644 - String getName() { return name; }
2.645 -
2.646 - String getDescriptor() { return descriptor; }
2.647 -
2.648 - }
2.649 -
2.650 - private static Class<?> toClass(Type o) {
2.651 - if (o instanceof GenericArrayType)
2.652 - return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
2.653 - 0)
2.654 - .getClass();
2.655 - return (Class<?>)o;
2.656 - }
2.657 -
2.658 - /**
2.659 - * If this {@code Class} object represents a local or anonymous
2.660 - * class within a constructor, returns a {@link
2.661 - * java.lang.reflect.Constructor Constructor} object representing
2.662 - * the immediately enclosing constructor of the underlying
2.663 - * class. Returns {@code null} otherwise. In particular, this
2.664 - * method returns {@code null} if the underlying class is a local
2.665 - * or anonymous class immediately enclosed by a type declaration,
2.666 - * instance initializer or static initializer.
2.667 - *
2.668 - * @return the immediately enclosing constructor of the underlying class, if
2.669 - * that class is a local or anonymous class; otherwise {@code null}.
2.670 - * @since 1.5
2.671 - */
2.672 - public Constructor<?> getEnclosingConstructor() {
2.673 - EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
2.674 -
2.675 - if (enclosingInfo == null)
2.676 - return null;
2.677 - else {
2.678 - if (!enclosingInfo.isConstructor())
2.679 - return null;
2.680 -
2.681 - ConstructorRepository typeInfo = ConstructorRepository.make(enclosingInfo.getDescriptor(),
2.682 - getFactory());
2.683 - Type [] parameterTypes = typeInfo.getParameterTypes();
2.684 - Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];
2.685 -
2.686 - // Convert Types to Classes; returned types *should*
2.687 - // be class objects since the methodDescriptor's used
2.688 - // don't have generics information
2.689 - for(int i = 0; i < parameterClasses.length; i++)
2.690 - parameterClasses[i] = toClass(parameterTypes[i]);
2.691 -
2.692 - /*
2.693 - * Loop over all declared constructors; match number
2.694 - * of and type of parameters.
2.695 - */
2.696 - for(Constructor<?> c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) {
2.697 - Class<?>[] candidateParamClasses = c.getParameterTypes();
2.698 - if (candidateParamClasses.length == parameterClasses.length) {
2.699 - boolean matches = true;
2.700 - for(int i = 0; i < candidateParamClasses.length; i++) {
2.701 - if (!candidateParamClasses[i].equals(parameterClasses[i])) {
2.702 - matches = false;
2.703 - break;
2.704 - }
2.705 - }
2.706 -
2.707 - if (matches)
2.708 - return c;
2.709 - }
2.710 - }
2.711 -
2.712 - throw new InternalError("Enclosing constructor not found");
2.713 - }
2.714 - }
2.715 -
2.716 -
2.717 - /**
2.718 - * If the class or interface represented by this {@code Class} object
2.719 - * is a member of another class, returns the {@code Class} object
2.720 - * representing the class in which it was declared. This method returns
2.721 - * null if this class or interface is not a member of any other class. If
2.722 - * this {@code Class} object represents an array class, a primitive
2.723 - * type, or void,then this method returns null.
2.724 - *
2.725 - * @return the declaring class for this class
2.726 - * @since JDK1.1
2.727 - */
2.728 - public native Class<?> getDeclaringClass();
2.729 -
2.730 -
2.731 - /**
2.732 - * Returns the immediately enclosing class of the underlying
2.733 - * class. If the underlying class is a top level class this
2.734 - * method returns {@code null}.
2.735 - * @return the immediately enclosing class of the underlying class
2.736 - * @since 1.5
2.737 - */
2.738 - public Class<?> getEnclosingClass() {
2.739 - // There are five kinds of classes (or interfaces):
2.740 - // a) Top level classes
2.741 - // b) Nested classes (static member classes)
2.742 - // c) Inner classes (non-static member classes)
2.743 - // d) Local classes (named classes declared within a method)
2.744 - // e) Anonymous classes
2.745 -
2.746 -
2.747 - // JVM Spec 4.8.6: A class must have an EnclosingMethod
2.748 - // attribute if and only if it is a local class or an
2.749 - // anonymous class.
2.750 - EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo();
2.751 -
2.752 - if (enclosingInfo == null) {
2.753 - // This is a top level or a nested class or an inner class (a, b, or c)
2.754 - return getDeclaringClass();
2.755 - } else {
2.756 - Class<?> enclosingClass = enclosingInfo.getEnclosingClass();
2.757 - // This is a local class or an anonymous class (d or e)
2.758 - if (enclosingClass == this || enclosingClass == null)
2.759 - throw new InternalError("Malformed enclosing method information");
2.760 - else
2.761 - return enclosingClass;
2.762 - }
2.763 - }
2.764 -
2.765 - /**
2.766 * Returns the simple name of the underlying class as given in the
2.767 * source code. Returns an empty string if the underlying class is
2.768 * anonymous.
2.769 @@ -1126,36 +444,37 @@
2.770 * @since 1.5
2.771 */
2.772 public String getSimpleName() {
2.773 - if (isArray())
2.774 - return getComponentType().getSimpleName()+"[]";
2.775 -
2.776 - String simpleName = getSimpleBinaryName();
2.777 - if (simpleName == null) { // top level class
2.778 - simpleName = getName();
2.779 - return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
2.780 - }
2.781 - // According to JLS3 "Binary Compatibility" (13.1) the binary
2.782 - // name of non-package classes (not top level) is the binary
2.783 - // name of the immediately enclosing class followed by a '$' followed by:
2.784 - // (for nested and inner classes): the simple name.
2.785 - // (for local classes): 1 or more digits followed by the simple name.
2.786 - // (for anonymous classes): 1 or more digits.
2.787 -
2.788 - // Since getSimpleBinaryName() will strip the binary name of
2.789 - // the immediatly enclosing class, we are now looking at a
2.790 - // string that matches the regular expression "\$[0-9]*"
2.791 - // followed by a simple name (considering the simple of an
2.792 - // anonymous class to be the empty string).
2.793 -
2.794 - // Remove leading "\$[0-9]*" from the name
2.795 - int length = simpleName.length();
2.796 - if (length < 1 || simpleName.charAt(0) != '$')
2.797 - throw new InternalError("Malformed class name");
2.798 - int index = 1;
2.799 - while (index < length && isAsciiDigit(simpleName.charAt(index)))
2.800 - index++;
2.801 - // Eventually, this is the empty string iff this is an anonymous class
2.802 - return simpleName.substring(index);
2.803 + throw new UnsupportedOperationException();
2.804 +//// if (isArray())
2.805 +//// return getComponentType().getSimpleName()+"[]";
2.806 +////
2.807 +//// String simpleName = getSimpleBinaryName();
2.808 +//// if (simpleName == null) { // top level class
2.809 +//// simpleName = getName();
2.810 +//// return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
2.811 +//// }
2.812 +//// // According to JLS3 "Binary Compatibility" (13.1) the binary
2.813 +//// // name of non-package classes (not top level) is the binary
2.814 +//// // name of the immediately enclosing class followed by a '$' followed by:
2.815 +//// // (for nested and inner classes): the simple name.
2.816 +//// // (for local classes): 1 or more digits followed by the simple name.
2.817 +//// // (for anonymous classes): 1 or more digits.
2.818 +////
2.819 +//// // Since getSimpleBinaryName() will strip the binary name of
2.820 +//// // the immediatly enclosing class, we are now looking at a
2.821 +//// // string that matches the regular expression "\$[0-9]*"
2.822 +//// // followed by a simple name (considering the simple of an
2.823 +//// // anonymous class to be the empty string).
2.824 +////
2.825 +//// // Remove leading "\$[0-9]*" from the name
2.826 +//// int length = simpleName.length();
2.827 +//// if (length < 1 || simpleName.charAt(0) != '$')
2.828 +//// throw new InternalError("Malformed class name");
2.829 +//// int index = 1;
2.830 +//// while (index < length && isAsciiDigit(simpleName.charAt(index)))
2.831 +//// index++;
2.832 +//// // Eventually, this is the empty string iff this is an anonymous class
2.833 +//// return simpleName.substring(index);
2.834 }
2.835
2.836 /**
2.837 @@ -1177,829 +496,25 @@
2.838 * @since 1.5
2.839 */
2.840 public String getCanonicalName() {
2.841 - if (isArray()) {
2.842 - String canonicalName = getComponentType().getCanonicalName();
2.843 - if (canonicalName != null)
2.844 - return canonicalName + "[]";
2.845 - else
2.846 - return null;
2.847 - }
2.848 - if (isLocalOrAnonymousClass())
2.849 - return null;
2.850 - Class<?> enclosingClass = getEnclosingClass();
2.851 - if (enclosingClass == null) { // top level class
2.852 - return getName();
2.853 - } else {
2.854 - String enclosingName = enclosingClass.getCanonicalName();
2.855 - if (enclosingName == null)
2.856 - return null;
2.857 - return enclosingName + "." + getSimpleName();
2.858 - }
2.859 - }
2.860 -
2.861 - /**
2.862 - * Returns {@code true} if and only if the underlying class
2.863 - * is an anonymous class.
2.864 - *
2.865 - * @return {@code true} if and only if this class is an anonymous class.
2.866 - * @since 1.5
2.867 - */
2.868 - public boolean isAnonymousClass() {
2.869 - return "".equals(getSimpleName());
2.870 - }
2.871 -
2.872 - /**
2.873 - * Returns {@code true} if and only if the underlying class
2.874 - * is a local class.
2.875 - *
2.876 - * @return {@code true} if and only if this class is a local class.
2.877 - * @since 1.5
2.878 - */
2.879 - public boolean isLocalClass() {
2.880 - return isLocalOrAnonymousClass() && !isAnonymousClass();
2.881 - }
2.882 -
2.883 - /**
2.884 - * Returns {@code true} if and only if the underlying class
2.885 - * is a member class.
2.886 - *
2.887 - * @return {@code true} if and only if this class is a member class.
2.888 - * @since 1.5
2.889 - */
2.890 - public boolean isMemberClass() {
2.891 - return getSimpleBinaryName() != null && !isLocalOrAnonymousClass();
2.892 - }
2.893 -
2.894 - /**
2.895 - * Returns the "simple binary name" of the underlying class, i.e.,
2.896 - * the binary name without the leading enclosing class name.
2.897 - * Returns {@code null} if the underlying class is a top level
2.898 - * class.
2.899 - */
2.900 - private String getSimpleBinaryName() {
2.901 - Class<?> enclosingClass = getEnclosingClass();
2.902 - if (enclosingClass == null) // top level class
2.903 - return null;
2.904 - // Otherwise, strip the enclosing class' name
2.905 - try {
2.906 - return getName().substring(enclosingClass.getName().length());
2.907 - } catch (IndexOutOfBoundsException ex) {
2.908 - throw new InternalError("Malformed class name");
2.909 - }
2.910 - }
2.911 -
2.912 - /**
2.913 - * Returns {@code true} if this is a local class or an anonymous
2.914 - * class. Returns {@code false} otherwise.
2.915 - */
2.916 - private boolean isLocalOrAnonymousClass() {
2.917 - // JVM Spec 4.8.6: A class must have an EnclosingMethod
2.918 - // attribute if and only if it is a local class or an
2.919 - // anonymous class.
2.920 - return getEnclosingMethodInfo() != null;
2.921 - }
2.922 -
2.923 - /**
2.924 - * Returns an array containing {@code Class} objects representing all
2.925 - * the public classes and interfaces that are members of the class
2.926 - * represented by this {@code Class} object. This includes public
2.927 - * class and interface members inherited from superclasses and public class
2.928 - * and interface members declared by the class. This method returns an
2.929 - * array of length 0 if this {@code Class} object has no public member
2.930 - * classes or interfaces. This method also returns an array of length 0 if
2.931 - * this {@code Class} object represents a primitive type, an array
2.932 - * class, or void.
2.933 - *
2.934 - * @return the array of {@code Class} objects representing the public
2.935 - * members of this class
2.936 - * @exception SecurityException
2.937 - * If a security manager, <i>s</i>, is present and any of the
2.938 - * following conditions is met:
2.939 - *
2.940 - * <ul>
2.941 - *
2.942 - * <li> invocation of
2.943 - * {@link SecurityManager#checkMemberAccess
2.944 - * s.checkMemberAccess(this, Member.PUBLIC)} method
2.945 - * denies access to the classes within this class
2.946 - *
2.947 - * <li> the caller's class loader is not the same as or an
2.948 - * ancestor of the class loader for the current class and
2.949 - * invocation of {@link SecurityManager#checkPackageAccess
2.950 - * s.checkPackageAccess()} denies access to the package
2.951 - * of this class
2.952 - *
2.953 - * </ul>
2.954 - *
2.955 - * @since JDK1.1
2.956 - */
2.957 - public Class<?>[] getClasses() {
2.958 - // be very careful not to change the stack depth of this
2.959 - // checkMemberAccess call for security reasons
2.960 - // see java.lang.SecurityManager.checkMemberAccess
2.961 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.962 -
2.963 - // Privileged so this implementation can look at DECLARED classes,
2.964 - // something the caller might not have privilege to do. The code here
2.965 - // is allowed to look at DECLARED classes because (1) it does not hand
2.966 - // out anything other than public members and (2) public member access
2.967 - // has already been ok'd by the SecurityManager.
2.968 -
2.969 - return java.security.AccessController.doPrivileged(
2.970 - new java.security.PrivilegedAction<Class<?>[]>() {
2.971 - public Class[] run() {
2.972 - List<Class<?>> list = new ArrayList<>();
2.973 - Class<?> currentClass = Class.this;
2.974 - while (currentClass != null) {
2.975 - Class<?>[] members = currentClass.getDeclaredClasses();
2.976 - for (int i = 0; i < members.length; i++) {
2.977 - if (Modifier.isPublic(members[i].getModifiers())) {
2.978 - list.add(members[i]);
2.979 - }
2.980 - }
2.981 - currentClass = currentClass.getSuperclass();
2.982 - }
2.983 - return list.toArray(new Class[0]);
2.984 - }
2.985 - });
2.986 - }
2.987 -
2.988 -
2.989 - /**
2.990 - * Returns an array containing {@code Field} objects reflecting all
2.991 - * the accessible public fields of the class or interface represented by
2.992 - * this {@code Class} object. The elements in the array returned are
2.993 - * not sorted and are not in any particular order. This method returns an
2.994 - * array of length 0 if the class or interface has no accessible public
2.995 - * fields, or if it represents an array class, a primitive type, or void.
2.996 - *
2.997 - * <p> Specifically, if this {@code Class} object represents a class,
2.998 - * this method returns the public fields of this class and of all its
2.999 - * superclasses. If this {@code Class} object represents an
2.1000 - * interface, this method returns the fields of this interface and of all
2.1001 - * its superinterfaces.
2.1002 - *
2.1003 - * <p> The implicit length field for array class is not reflected by this
2.1004 - * method. User code should use the methods of class {@code Array} to
2.1005 - * manipulate arrays.
2.1006 - *
2.1007 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
2.1008 - *
2.1009 - * @return the array of {@code Field} objects representing the
2.1010 - * public fields
2.1011 - * @exception SecurityException
2.1012 - * If a security manager, <i>s</i>, is present and any of the
2.1013 - * following conditions is met:
2.1014 - *
2.1015 - * <ul>
2.1016 - *
2.1017 - * <li> invocation of
2.1018 - * {@link SecurityManager#checkMemberAccess
2.1019 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.1020 - * access to the fields within this class
2.1021 - *
2.1022 - * <li> the caller's class loader is not the same as or an
2.1023 - * ancestor of the class loader for the current class and
2.1024 - * invocation of {@link SecurityManager#checkPackageAccess
2.1025 - * s.checkPackageAccess()} denies access to the package
2.1026 - * of this class
2.1027 - *
2.1028 - * </ul>
2.1029 - *
2.1030 - * @since JDK1.1
2.1031 - */
2.1032 - public Field[] getFields() throws SecurityException {
2.1033 - // be very careful not to change the stack depth of this
2.1034 - // checkMemberAccess call for security reasons
2.1035 - // see java.lang.SecurityManager.checkMemberAccess
2.1036 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.1037 - return copyFields(privateGetPublicFields(null));
2.1038 - }
2.1039 -
2.1040 -
2.1041 - /**
2.1042 - * Returns an array containing {@code Method} objects reflecting all
2.1043 - * the public <em>member</em> methods of the class or interface represented
2.1044 - * by this {@code Class} object, including those declared by the class
2.1045 - * or interface and those inherited from superclasses and
2.1046 - * superinterfaces. Array classes return all the (public) member methods
2.1047 - * inherited from the {@code Object} class. The elements in the array
2.1048 - * returned are not sorted and are not in any particular order. This
2.1049 - * method returns an array of length 0 if this {@code Class} object
2.1050 - * represents a class or interface that has no public member methods, or if
2.1051 - * this {@code Class} object represents a primitive type or void.
2.1052 - *
2.1053 - * <p> The class initialization method {@code <clinit>} is not
2.1054 - * included in the returned array. If the class declares multiple public
2.1055 - * member methods with the same parameter types, they are all included in
2.1056 - * the returned array.
2.1057 - *
2.1058 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
2.1059 - *
2.1060 - * @return the array of {@code Method} objects representing the
2.1061 - * public methods of this class
2.1062 - * @exception SecurityException
2.1063 - * If a security manager, <i>s</i>, is present and any of the
2.1064 - * following conditions is met:
2.1065 - *
2.1066 - * <ul>
2.1067 - *
2.1068 - * <li> invocation of
2.1069 - * {@link SecurityManager#checkMemberAccess
2.1070 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.1071 - * access to the methods within this class
2.1072 - *
2.1073 - * <li> the caller's class loader is not the same as or an
2.1074 - * ancestor of the class loader for the current class and
2.1075 - * invocation of {@link SecurityManager#checkPackageAccess
2.1076 - * s.checkPackageAccess()} denies access to the package
2.1077 - * of this class
2.1078 - *
2.1079 - * </ul>
2.1080 - *
2.1081 - * @since JDK1.1
2.1082 - */
2.1083 - public Method[] getMethods() throws SecurityException {
2.1084 - // be very careful not to change the stack depth of this
2.1085 - // checkMemberAccess call for security reasons
2.1086 - // see java.lang.SecurityManager.checkMemberAccess
2.1087 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.1088 - return copyMethods(privateGetPublicMethods());
2.1089 - }
2.1090 -
2.1091 -
2.1092 - /**
2.1093 - * Returns an array containing {@code Constructor} objects reflecting
2.1094 - * all the public constructors of the class represented by this
2.1095 - * {@code Class} object. An array of length 0 is returned if the
2.1096 - * class has no public constructors, or if the class is an array class, or
2.1097 - * if the class reflects a primitive type or void.
2.1098 - *
2.1099 - * Note that while this method returns an array of {@code
2.1100 - * Constructor<T>} objects (that is an array of constructors from
2.1101 - * this class), the return type of this method is {@code
2.1102 - * Constructor<?>[]} and <em>not</em> {@code Constructor<T>[]} as
2.1103 - * might be expected. This less informative return type is
2.1104 - * necessary since after being returned from this method, the
2.1105 - * array could be modified to hold {@code Constructor} objects for
2.1106 - * different classes, which would violate the type guarantees of
2.1107 - * {@code Constructor<T>[]}.
2.1108 - *
2.1109 - * @return the array of {@code Constructor} objects representing the
2.1110 - * public constructors of this class
2.1111 - * @exception SecurityException
2.1112 - * If a security manager, <i>s</i>, is present and any of the
2.1113 - * following conditions is met:
2.1114 - *
2.1115 - * <ul>
2.1116 - *
2.1117 - * <li> invocation of
2.1118 - * {@link SecurityManager#checkMemberAccess
2.1119 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.1120 - * access to the constructors within this class
2.1121 - *
2.1122 - * <li> the caller's class loader is not the same as or an
2.1123 - * ancestor of the class loader for the current class and
2.1124 - * invocation of {@link SecurityManager#checkPackageAccess
2.1125 - * s.checkPackageAccess()} denies access to the package
2.1126 - * of this class
2.1127 - *
2.1128 - * </ul>
2.1129 - *
2.1130 - * @since JDK1.1
2.1131 - */
2.1132 - public Constructor<?>[] getConstructors() throws SecurityException {
2.1133 - // be very careful not to change the stack depth of this
2.1134 - // checkMemberAccess call for security reasons
2.1135 - // see java.lang.SecurityManager.checkMemberAccess
2.1136 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.1137 - return copyConstructors(privateGetDeclaredConstructors(true));
2.1138 - }
2.1139 -
2.1140 -
2.1141 - /**
2.1142 - * Returns a {@code Field} object that reflects the specified public
2.1143 - * member field of the class or interface represented by this
2.1144 - * {@code Class} object. The {@code name} parameter is a
2.1145 - * {@code String} specifying the simple name of the desired field.
2.1146 - *
2.1147 - * <p> The field to be reflected is determined by the algorithm that
2.1148 - * follows. Let C be the class represented by this object:
2.1149 - * <OL>
2.1150 - * <LI> If C declares a public field with the name specified, that is the
2.1151 - * field to be reflected.</LI>
2.1152 - * <LI> If no field was found in step 1 above, this algorithm is applied
2.1153 - * recursively to each direct superinterface of C. The direct
2.1154 - * superinterfaces are searched in the order they were declared.</LI>
2.1155 - * <LI> If no field was found in steps 1 and 2 above, and C has a
2.1156 - * superclass S, then this algorithm is invoked recursively upon S.
2.1157 - * If C has no superclass, then a {@code NoSuchFieldException}
2.1158 - * is thrown.</LI>
2.1159 - * </OL>
2.1160 - *
2.1161 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
2.1162 - *
2.1163 - * @param name the field name
2.1164 - * @return the {@code Field} object of this class specified by
2.1165 - * {@code name}
2.1166 - * @exception NoSuchFieldException if a field with the specified name is
2.1167 - * not found.
2.1168 - * @exception NullPointerException if {@code name} is {@code null}
2.1169 - * @exception SecurityException
2.1170 - * If a security manager, <i>s</i>, is present and any of the
2.1171 - * following conditions is met:
2.1172 - *
2.1173 - * <ul>
2.1174 - *
2.1175 - * <li> invocation of
2.1176 - * {@link SecurityManager#checkMemberAccess
2.1177 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.1178 - * access to the field
2.1179 - *
2.1180 - * <li> the caller's class loader is not the same as or an
2.1181 - * ancestor of the class loader for the current class and
2.1182 - * invocation of {@link SecurityManager#checkPackageAccess
2.1183 - * s.checkPackageAccess()} denies access to the package
2.1184 - * of this class
2.1185 - *
2.1186 - * </ul>
2.1187 - *
2.1188 - * @since JDK1.1
2.1189 - */
2.1190 - public Field getField(String name)
2.1191 - throws NoSuchFieldException, SecurityException {
2.1192 - // be very careful not to change the stack depth of this
2.1193 - // checkMemberAccess call for security reasons
2.1194 - // see java.lang.SecurityManager.checkMemberAccess
2.1195 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.1196 - Field field = getField0(name);
2.1197 - if (field == null) {
2.1198 - throw new NoSuchFieldException(name);
2.1199 - }
2.1200 - return field;
2.1201 - }
2.1202 -
2.1203 -
2.1204 - /**
2.1205 - * Returns a {@code Method} object that reflects the specified public
2.1206 - * member method of the class or interface represented by this
2.1207 - * {@code Class} object. The {@code name} parameter is a
2.1208 - * {@code String} specifying the simple name of the desired method. The
2.1209 - * {@code parameterTypes} parameter is an array of {@code Class}
2.1210 - * objects that identify the method's formal parameter types, in declared
2.1211 - * order. If {@code parameterTypes} is {@code null}, it is
2.1212 - * treated as if it were an empty array.
2.1213 - *
2.1214 - * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
2.1215 - * {@code NoSuchMethodException} is raised. Otherwise, the method to
2.1216 - * be reflected is determined by the algorithm that follows. Let C be the
2.1217 - * class represented by this object:
2.1218 - * <OL>
2.1219 - * <LI> C is searched for any <I>matching methods</I>. If no matching
2.1220 - * method is found, the algorithm of step 1 is invoked recursively on
2.1221 - * the superclass of C.</LI>
2.1222 - * <LI> If no method was found in step 1 above, the superinterfaces of C
2.1223 - * are searched for a matching method. If any such method is found, it
2.1224 - * is reflected.</LI>
2.1225 - * </OL>
2.1226 - *
2.1227 - * To find a matching method in a class C: If C declares exactly one
2.1228 - * public method with the specified name and exactly the same formal
2.1229 - * parameter types, that is the method reflected. If more than one such
2.1230 - * method is found in C, and one of these methods has a return type that is
2.1231 - * more specific than any of the others, that method is reflected;
2.1232 - * otherwise one of the methods is chosen arbitrarily.
2.1233 - *
2.1234 - * <p>Note that there may be more than one matching method in a
2.1235 - * class because while the Java language forbids a class to
2.1236 - * declare multiple methods with the same signature but different
2.1237 - * return types, the Java virtual machine does not. This
2.1238 - * increased flexibility in the virtual machine can be used to
2.1239 - * implement various language features. For example, covariant
2.1240 - * returns can be implemented with {@linkplain
2.1241 - * java.lang.reflect.Method#isBridge bridge methods}; the bridge
2.1242 - * method and the method being overridden would have the same
2.1243 - * signature but different return types.
2.1244 - *
2.1245 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
2.1246 - *
2.1247 - * @param name the name of the method
2.1248 - * @param parameterTypes the list of parameters
2.1249 - * @return the {@code Method} object that matches the specified
2.1250 - * {@code name} and {@code parameterTypes}
2.1251 - * @exception NoSuchMethodException if a matching method is not found
2.1252 - * or if the name is "<init>"or "<clinit>".
2.1253 - * @exception NullPointerException if {@code name} is {@code null}
2.1254 - * @exception SecurityException
2.1255 - * If a security manager, <i>s</i>, is present and any of the
2.1256 - * following conditions is met:
2.1257 - *
2.1258 - * <ul>
2.1259 - *
2.1260 - * <li> invocation of
2.1261 - * {@link SecurityManager#checkMemberAccess
2.1262 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.1263 - * access to the method
2.1264 - *
2.1265 - * <li> the caller's class loader is not the same as or an
2.1266 - * ancestor of the class loader for the current class and
2.1267 - * invocation of {@link SecurityManager#checkPackageAccess
2.1268 - * s.checkPackageAccess()} denies access to the package
2.1269 - * of this class
2.1270 - *
2.1271 - * </ul>
2.1272 - *
2.1273 - * @since JDK1.1
2.1274 - */
2.1275 - public Method getMethod(String name, Class<?>... parameterTypes)
2.1276 - throws NoSuchMethodException, SecurityException {
2.1277 - // be very careful not to change the stack depth of this
2.1278 - // checkMemberAccess call for security reasons
2.1279 - // see java.lang.SecurityManager.checkMemberAccess
2.1280 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.1281 - Method method = getMethod0(name, parameterTypes);
2.1282 - if (method == null) {
2.1283 - throw new NoSuchMethodException(getName() + "." + name + argumentTypesToString(parameterTypes));
2.1284 - }
2.1285 - return method;
2.1286 - }
2.1287 -
2.1288 -
2.1289 - /**
2.1290 - * Returns a {@code Constructor} object that reflects the specified
2.1291 - * public constructor of the class represented by this {@code Class}
2.1292 - * object. The {@code parameterTypes} parameter is an array of
2.1293 - * {@code Class} objects that identify the constructor's formal
2.1294 - * parameter types, in declared order.
2.1295 - *
2.1296 - * If this {@code Class} object represents an inner class
2.1297 - * declared in a non-static context, the formal parameter types
2.1298 - * include the explicit enclosing instance as the first parameter.
2.1299 - *
2.1300 - * <p> The constructor to reflect is the public constructor of the class
2.1301 - * represented by this {@code Class} object whose formal parameter
2.1302 - * types match those specified by {@code parameterTypes}.
2.1303 - *
2.1304 - * @param parameterTypes the parameter array
2.1305 - * @return the {@code Constructor} object of the public constructor that
2.1306 - * matches the specified {@code parameterTypes}
2.1307 - * @exception NoSuchMethodException if a matching method is not found.
2.1308 - * @exception SecurityException
2.1309 - * If a security manager, <i>s</i>, is present and any of the
2.1310 - * following conditions is met:
2.1311 - *
2.1312 - * <ul>
2.1313 - *
2.1314 - * <li> invocation of
2.1315 - * {@link SecurityManager#checkMemberAccess
2.1316 - * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.1317 - * access to the constructor
2.1318 - *
2.1319 - * <li> the caller's class loader is not the same as or an
2.1320 - * ancestor of the class loader for the current class and
2.1321 - * invocation of {@link SecurityManager#checkPackageAccess
2.1322 - * s.checkPackageAccess()} denies access to the package
2.1323 - * of this class
2.1324 - *
2.1325 - * </ul>
2.1326 - *
2.1327 - * @since JDK1.1
2.1328 - */
2.1329 - public Constructor<T> getConstructor(Class<?>... parameterTypes)
2.1330 - throws NoSuchMethodException, SecurityException {
2.1331 - // be very careful not to change the stack depth of this
2.1332 - // checkMemberAccess call for security reasons
2.1333 - // see java.lang.SecurityManager.checkMemberAccess
2.1334 - checkMemberAccess(Member.PUBLIC, ClassLoader.getCallerClassLoader());
2.1335 - return getConstructor0(parameterTypes, Member.PUBLIC);
2.1336 - }
2.1337 -
2.1338 -
2.1339 - /**
2.1340 - * Returns an array of {@code Class} objects reflecting all the
2.1341 - * classes and interfaces declared as members of the class represented by
2.1342 - * this {@code Class} object. This includes public, protected, default
2.1343 - * (package) access, and private classes and interfaces declared by the
2.1344 - * class, but excludes inherited classes and interfaces. This method
2.1345 - * returns an array of length 0 if the class declares no classes or
2.1346 - * interfaces as members, or if this {@code Class} object represents a
2.1347 - * primitive type, an array class, or void.
2.1348 - *
2.1349 - * @return the array of {@code Class} objects representing all the
2.1350 - * declared members of this class
2.1351 - * @exception SecurityException
2.1352 - * If a security manager, <i>s</i>, is present and any of the
2.1353 - * following conditions is met:
2.1354 - *
2.1355 - * <ul>
2.1356 - *
2.1357 - * <li> invocation of
2.1358 - * {@link SecurityManager#checkMemberAccess
2.1359 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1360 - * access to the declared classes within this class
2.1361 - *
2.1362 - * <li> the caller's class loader is not the same as or an
2.1363 - * ancestor of the class loader for the current class and
2.1364 - * invocation of {@link SecurityManager#checkPackageAccess
2.1365 - * s.checkPackageAccess()} denies access to the package
2.1366 - * of this class
2.1367 - *
2.1368 - * </ul>
2.1369 - *
2.1370 - * @since JDK1.1
2.1371 - */
2.1372 - public Class<?>[] getDeclaredClasses() throws SecurityException {
2.1373 - // be very careful not to change the stack depth of this
2.1374 - // checkMemberAccess call for security reasons
2.1375 - // see java.lang.SecurityManager.checkMemberAccess
2.1376 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1377 - return getDeclaredClasses0();
2.1378 - }
2.1379 -
2.1380 -
2.1381 - /**
2.1382 - * Returns an array of {@code Field} objects reflecting all the fields
2.1383 - * declared by the class or interface represented by this
2.1384 - * {@code Class} object. This includes public, protected, default
2.1385 - * (package) access, and private fields, but excludes inherited fields.
2.1386 - * The elements in the array returned are not sorted and are not in any
2.1387 - * particular order. This method returns an array of length 0 if the class
2.1388 - * or interface declares no fields, or if this {@code Class} object
2.1389 - * represents a primitive type, an array class, or void.
2.1390 - *
2.1391 - * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
2.1392 - *
2.1393 - * @return the array of {@code Field} objects representing all the
2.1394 - * declared fields of this class
2.1395 - * @exception SecurityException
2.1396 - * If a security manager, <i>s</i>, is present and any of the
2.1397 - * following conditions is met:
2.1398 - *
2.1399 - * <ul>
2.1400 - *
2.1401 - * <li> invocation of
2.1402 - * {@link SecurityManager#checkMemberAccess
2.1403 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1404 - * access to the declared fields within this class
2.1405 - *
2.1406 - * <li> the caller's class loader is not the same as or an
2.1407 - * ancestor of the class loader for the current class and
2.1408 - * invocation of {@link SecurityManager#checkPackageAccess
2.1409 - * s.checkPackageAccess()} denies access to the package
2.1410 - * of this class
2.1411 - *
2.1412 - * </ul>
2.1413 - *
2.1414 - * @since JDK1.1
2.1415 - */
2.1416 - public Field[] getDeclaredFields() throws SecurityException {
2.1417 - // be very careful not to change the stack depth of this
2.1418 - // checkMemberAccess call for security reasons
2.1419 - // see java.lang.SecurityManager.checkMemberAccess
2.1420 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1421 - return copyFields(privateGetDeclaredFields(false));
2.1422 - }
2.1423 -
2.1424 -
2.1425 - /**
2.1426 - * Returns an array of {@code Method} objects reflecting all the
2.1427 - * methods declared by the class or interface represented by this
2.1428 - * {@code Class} object. This includes public, protected, default
2.1429 - * (package) access, and private methods, but excludes inherited methods.
2.1430 - * The elements in the array returned are not sorted and are not in any
2.1431 - * particular order. This method returns an array of length 0 if the class
2.1432 - * or interface declares no methods, or if this {@code Class} object
2.1433 - * represents a primitive type, an array class, or void. The class
2.1434 - * initialization method {@code <clinit>} is not included in the
2.1435 - * returned array. If the class declares multiple public member methods
2.1436 - * with the same parameter types, they are all included in the returned
2.1437 - * array.
2.1438 - *
2.1439 - * <p> See <em>The Java Language Specification</em>, section 8.2.
2.1440 - *
2.1441 - * @return the array of {@code Method} objects representing all the
2.1442 - * declared methods of this class
2.1443 - * @exception SecurityException
2.1444 - * If a security manager, <i>s</i>, is present and any of the
2.1445 - * following conditions is met:
2.1446 - *
2.1447 - * <ul>
2.1448 - *
2.1449 - * <li> invocation of
2.1450 - * {@link SecurityManager#checkMemberAccess
2.1451 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1452 - * access to the declared methods within this class
2.1453 - *
2.1454 - * <li> the caller's class loader is not the same as or an
2.1455 - * ancestor of the class loader for the current class and
2.1456 - * invocation of {@link SecurityManager#checkPackageAccess
2.1457 - * s.checkPackageAccess()} denies access to the package
2.1458 - * of this class
2.1459 - *
2.1460 - * </ul>
2.1461 - *
2.1462 - * @since JDK1.1
2.1463 - */
2.1464 - public Method[] getDeclaredMethods() throws SecurityException {
2.1465 - // be very careful not to change the stack depth of this
2.1466 - // checkMemberAccess call for security reasons
2.1467 - // see java.lang.SecurityManager.checkMemberAccess
2.1468 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1469 - return copyMethods(privateGetDeclaredMethods(false));
2.1470 - }
2.1471 -
2.1472 -
2.1473 - /**
2.1474 - * Returns an array of {@code Constructor} objects reflecting all the
2.1475 - * constructors declared by the class represented by this
2.1476 - * {@code Class} object. These are public, protected, default
2.1477 - * (package) access, and private constructors. The elements in the array
2.1478 - * returned are not sorted and are not in any particular order. If the
2.1479 - * class has a default constructor, it is included in the returned array.
2.1480 - * This method returns an array of length 0 if this {@code Class}
2.1481 - * object represents an interface, a primitive type, an array class, or
2.1482 - * void.
2.1483 - *
2.1484 - * <p> See <em>The Java Language Specification</em>, section 8.2.
2.1485 - *
2.1486 - * @return the array of {@code Constructor} objects representing all the
2.1487 - * declared constructors of this class
2.1488 - * @exception SecurityException
2.1489 - * If a security manager, <i>s</i>, is present and any of the
2.1490 - * following conditions is met:
2.1491 - *
2.1492 - * <ul>
2.1493 - *
2.1494 - * <li> invocation of
2.1495 - * {@link SecurityManager#checkMemberAccess
2.1496 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1497 - * access to the declared constructors within this class
2.1498 - *
2.1499 - * <li> the caller's class loader is not the same as or an
2.1500 - * ancestor of the class loader for the current class and
2.1501 - * invocation of {@link SecurityManager#checkPackageAccess
2.1502 - * s.checkPackageAccess()} denies access to the package
2.1503 - * of this class
2.1504 - *
2.1505 - * </ul>
2.1506 - *
2.1507 - * @since JDK1.1
2.1508 - */
2.1509 - public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
2.1510 - // be very careful not to change the stack depth of this
2.1511 - // checkMemberAccess call for security reasons
2.1512 - // see java.lang.SecurityManager.checkMemberAccess
2.1513 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1514 - return copyConstructors(privateGetDeclaredConstructors(false));
2.1515 - }
2.1516 -
2.1517 -
2.1518 - /**
2.1519 - * Returns a {@code Field} object that reflects the specified declared
2.1520 - * field of the class or interface represented by this {@code Class}
2.1521 - * object. The {@code name} parameter is a {@code String} that
2.1522 - * specifies the simple name of the desired field. Note that this method
2.1523 - * will not reflect the {@code length} field of an array class.
2.1524 - *
2.1525 - * @param name the name of the field
2.1526 - * @return the {@code Field} object for the specified field in this
2.1527 - * class
2.1528 - * @exception NoSuchFieldException if a field with the specified name is
2.1529 - * not found.
2.1530 - * @exception NullPointerException if {@code name} is {@code null}
2.1531 - * @exception SecurityException
2.1532 - * If a security manager, <i>s</i>, is present and any of the
2.1533 - * following conditions is met:
2.1534 - *
2.1535 - * <ul>
2.1536 - *
2.1537 - * <li> invocation of
2.1538 - * {@link SecurityManager#checkMemberAccess
2.1539 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1540 - * access to the declared field
2.1541 - *
2.1542 - * <li> the caller's class loader is not the same as or an
2.1543 - * ancestor of the class loader for the current class and
2.1544 - * invocation of {@link SecurityManager#checkPackageAccess
2.1545 - * s.checkPackageAccess()} denies access to the package
2.1546 - * of this class
2.1547 - *
2.1548 - * </ul>
2.1549 - *
2.1550 - * @since JDK1.1
2.1551 - */
2.1552 - public Field getDeclaredField(String name)
2.1553 - throws NoSuchFieldException, SecurityException {
2.1554 - // be very careful not to change the stack depth of this
2.1555 - // checkMemberAccess call for security reasons
2.1556 - // see java.lang.SecurityManager.checkMemberAccess
2.1557 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1558 - Field field = searchFields(privateGetDeclaredFields(false), name);
2.1559 - if (field == null) {
2.1560 - throw new NoSuchFieldException(name);
2.1561 - }
2.1562 - return field;
2.1563 - }
2.1564 -
2.1565 -
2.1566 - /**
2.1567 - * Returns a {@code Method} object that reflects the specified
2.1568 - * declared method of the class or interface represented by this
2.1569 - * {@code Class} object. The {@code name} parameter is a
2.1570 - * {@code String} that specifies the simple name of the desired
2.1571 - * method, and the {@code parameterTypes} parameter is an array of
2.1572 - * {@code Class} objects that identify the method's formal parameter
2.1573 - * types, in declared order. If more than one method with the same
2.1574 - * parameter types is declared in a class, and one of these methods has a
2.1575 - * return type that is more specific than any of the others, that method is
2.1576 - * returned; otherwise one of the methods is chosen arbitrarily. If the
2.1577 - * name is "<init>"or "<clinit>" a {@code NoSuchMethodException}
2.1578 - * is raised.
2.1579 - *
2.1580 - * @param name the name of the method
2.1581 - * @param parameterTypes the parameter array
2.1582 - * @return the {@code Method} object for the method of this class
2.1583 - * matching the specified name and parameters
2.1584 - * @exception NoSuchMethodException if a matching method is not found.
2.1585 - * @exception NullPointerException if {@code name} is {@code null}
2.1586 - * @exception SecurityException
2.1587 - * If a security manager, <i>s</i>, is present and any of the
2.1588 - * following conditions is met:
2.1589 - *
2.1590 - * <ul>
2.1591 - *
2.1592 - * <li> invocation of
2.1593 - * {@link SecurityManager#checkMemberAccess
2.1594 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1595 - * access to the declared method
2.1596 - *
2.1597 - * <li> the caller's class loader is not the same as or an
2.1598 - * ancestor of the class loader for the current class and
2.1599 - * invocation of {@link SecurityManager#checkPackageAccess
2.1600 - * s.checkPackageAccess()} denies access to the package
2.1601 - * of this class
2.1602 - *
2.1603 - * </ul>
2.1604 - *
2.1605 - * @since JDK1.1
2.1606 - */
2.1607 - public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
2.1608 - throws NoSuchMethodException, SecurityException {
2.1609 - // be very careful not to change the stack depth of this
2.1610 - // checkMemberAccess call for security reasons
2.1611 - // see java.lang.SecurityManager.checkMemberAccess
2.1612 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1613 - Method method = searchMethods(privateGetDeclaredMethods(false), name, parameterTypes);
2.1614 - if (method == null) {
2.1615 - throw new NoSuchMethodException(getName() + "." + name + argumentTypesToString(parameterTypes));
2.1616 - }
2.1617 - return method;
2.1618 - }
2.1619 -
2.1620 -
2.1621 - /**
2.1622 - * Returns a {@code Constructor} object that reflects the specified
2.1623 - * constructor of the class or interface represented by this
2.1624 - * {@code Class} object. The {@code parameterTypes} parameter is
2.1625 - * an array of {@code Class} objects that identify the constructor's
2.1626 - * formal parameter types, in declared order.
2.1627 - *
2.1628 - * If this {@code Class} object represents an inner class
2.1629 - * declared in a non-static context, the formal parameter types
2.1630 - * include the explicit enclosing instance as the first parameter.
2.1631 - *
2.1632 - * @param parameterTypes the parameter array
2.1633 - * @return The {@code Constructor} object for the constructor with the
2.1634 - * specified parameter list
2.1635 - * @exception NoSuchMethodException if a matching method is not found.
2.1636 - * @exception SecurityException
2.1637 - * If a security manager, <i>s</i>, is present and any of the
2.1638 - * following conditions is met:
2.1639 - *
2.1640 - * <ul>
2.1641 - *
2.1642 - * <li> invocation of
2.1643 - * {@link SecurityManager#checkMemberAccess
2.1644 - * s.checkMemberAccess(this, Member.DECLARED)} denies
2.1645 - * access to the declared constructor
2.1646 - *
2.1647 - * <li> the caller's class loader is not the same as or an
2.1648 - * ancestor of the class loader for the current class and
2.1649 - * invocation of {@link SecurityManager#checkPackageAccess
2.1650 - * s.checkPackageAccess()} denies access to the package
2.1651 - * of this class
2.1652 - *
2.1653 - * </ul>
2.1654 - *
2.1655 - * @since JDK1.1
2.1656 - */
2.1657 - public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
2.1658 - throws NoSuchMethodException, SecurityException {
2.1659 - // be very careful not to change the stack depth of this
2.1660 - // checkMemberAccess call for security reasons
2.1661 - // see java.lang.SecurityManager.checkMemberAccess
2.1662 - checkMemberAccess(Member.DECLARED, ClassLoader.getCallerClassLoader());
2.1663 - return getConstructor0(parameterTypes, Member.DECLARED);
2.1664 + throw new UnsupportedOperationException();
2.1665 +// if (isArray()) {
2.1666 +// String canonicalName = getComponentType().getCanonicalName();
2.1667 +// if (canonicalName != null)
2.1668 +// return canonicalName + "[]";
2.1669 +// else
2.1670 +// return null;
2.1671 +// }
2.1672 +// if (isLocalOrAnonymousClass())
2.1673 +// return null;
2.1674 +// Class<?> enclosingClass = getEnclosingClass();
2.1675 +// if (enclosingClass == null) { // top level class
2.1676 +// return getName();
2.1677 +// } else {
2.1678 +// String enclosingName = enclosingClass.getCanonicalName();
2.1679 +// if (enclosingName == null)
2.1680 +// return null;
2.1681 +// return enclosingName + "." + getSimpleName();
2.1682 +// }
2.1683 }
2.1684
2.1685 /**
2.1686 @@ -2037,15 +552,15 @@
2.1687 * @throws NullPointerException If {@code name} is {@code null}
2.1688 * @since JDK1.1
2.1689 */
2.1690 - public InputStream getResourceAsStream(String name) {
2.1691 - name = resolveName(name);
2.1692 - ClassLoader cl = getClassLoader0();
2.1693 - if (cl==null) {
2.1694 - // A system class.
2.1695 - return ClassLoader.getSystemResourceAsStream(name);
2.1696 - }
2.1697 - return cl.getResourceAsStream(name);
2.1698 - }
2.1699 +// public InputStream getResourceAsStream(String name) {
2.1700 +// name = resolveName(name);
2.1701 +// ClassLoader cl = getClassLoader0();
2.1702 +// if (cl==null) {
2.1703 +// // A system class.
2.1704 +// return ClassLoader.getSystemResourceAsStream(name);
2.1705 +// }
2.1706 +// return cl.getResourceAsStream(name);
2.1707 +// }
2.1708
2.1709 /**
2.1710 * Finds a resource with a given name. The rules for searching resources
2.1711 @@ -2081,786 +596,18 @@
2.1712 * resource with this name is found
2.1713 * @since JDK1.1
2.1714 */
2.1715 - public java.net.URL getResource(String name) {
2.1716 - name = resolveName(name);
2.1717 - ClassLoader cl = getClassLoader0();
2.1718 - if (cl==null) {
2.1719 - // A system class.
2.1720 - return ClassLoader.getSystemResource(name);
2.1721 - }
2.1722 - return cl.getResource(name);
2.1723 - }
2.1724 +// public java.net.URL getResource(String name) {
2.1725 +// name = resolveName(name);
2.1726 +// ClassLoader cl = getClassLoader0();
2.1727 +// if (cl==null) {
2.1728 +// // A system class.
2.1729 +// return ClassLoader.getSystemResource(name);
2.1730 +// }
2.1731 +// return cl.getResource(name);
2.1732 +// }
2.1733
2.1734
2.1735
2.1736 - /** protection domain returned when the internal domain is null */
2.1737 - private static java.security.ProtectionDomain allPermDomain;
2.1738 -
2.1739 -
2.1740 - /**
2.1741 - * Returns the {@code ProtectionDomain} of this class. If there is a
2.1742 - * security manager installed, this method first calls the security
2.1743 - * manager's {@code checkPermission} method with a
2.1744 - * {@code RuntimePermission("getProtectionDomain")} permission to
2.1745 - * ensure it's ok to get the
2.1746 - * {@code ProtectionDomain}.
2.1747 - *
2.1748 - * @return the ProtectionDomain of this class
2.1749 - *
2.1750 - * @throws SecurityException
2.1751 - * if a security manager exists and its
2.1752 - * {@code checkPermission} method doesn't allow
2.1753 - * getting the ProtectionDomain.
2.1754 - *
2.1755 - * @see java.security.ProtectionDomain
2.1756 - * @see SecurityManager#checkPermission
2.1757 - * @see java.lang.RuntimePermission
2.1758 - * @since 1.2
2.1759 - */
2.1760 - public java.security.ProtectionDomain getProtectionDomain() {
2.1761 - SecurityManager sm = System.getSecurityManager();
2.1762 - if (sm != null) {
2.1763 - sm.checkPermission(SecurityConstants.GET_PD_PERMISSION);
2.1764 - }
2.1765 - java.security.ProtectionDomain pd = getProtectionDomain0();
2.1766 - if (pd == null) {
2.1767 - if (allPermDomain == null) {
2.1768 - java.security.Permissions perms =
2.1769 - new java.security.Permissions();
2.1770 - perms.add(SecurityConstants.ALL_PERMISSION);
2.1771 - allPermDomain =
2.1772 - new java.security.ProtectionDomain(null, perms);
2.1773 - }
2.1774 - pd = allPermDomain;
2.1775 - }
2.1776 - return pd;
2.1777 - }
2.1778 -
2.1779 -
2.1780 - /**
2.1781 - * Returns the ProtectionDomain of this class.
2.1782 - */
2.1783 - private native java.security.ProtectionDomain getProtectionDomain0();
2.1784 -
2.1785 -
2.1786 - /**
2.1787 - * Set the ProtectionDomain for this class. Called by
2.1788 - * ClassLoader.defineClass.
2.1789 - */
2.1790 - native void setProtectionDomain0(java.security.ProtectionDomain pd);
2.1791 -
2.1792 -
2.1793 - /*
2.1794 - * Return the Virtual Machine's Class object for the named
2.1795 - * primitive type.
2.1796 - */
2.1797 - static native Class getPrimitiveClass(String name);
2.1798 -
2.1799 -
2.1800 - /*
2.1801 - * Check if client is allowed to access members. If access is denied,
2.1802 - * throw a SecurityException.
2.1803 - *
2.1804 - * Be very careful not to change the stack depth of this checkMemberAccess
2.1805 - * call for security reasons.
2.1806 - * See java.lang.SecurityManager.checkMemberAccess.
2.1807 - *
2.1808 - * <p> Default policy: allow all clients access with normal Java access
2.1809 - * control.
2.1810 - */
2.1811 - private void checkMemberAccess(int which, ClassLoader ccl) {
2.1812 - SecurityManager s = System.getSecurityManager();
2.1813 - if (s != null) {
2.1814 - s.checkMemberAccess(this, which);
2.1815 - ClassLoader cl = getClassLoader0();
2.1816 - if ((ccl != null) && (ccl != cl) &&
2.1817 - ((cl == null) || !cl.isAncestor(ccl))) {
2.1818 - String name = this.getName();
2.1819 - int i = name.lastIndexOf('.');
2.1820 - if (i != -1) {
2.1821 - s.checkPackageAccess(name.substring(0, i));
2.1822 - }
2.1823 - }
2.1824 - }
2.1825 - }
2.1826 -
2.1827 - /**
2.1828 - * Add a package name prefix if the name is not absolute Remove leading "/"
2.1829 - * if name is absolute
2.1830 - */
2.1831 - private String resolveName(String name) {
2.1832 - if (name == null) {
2.1833 - return name;
2.1834 - }
2.1835 - if (!name.startsWith("/")) {
2.1836 - Class<?> c = this;
2.1837 - while (c.isArray()) {
2.1838 - c = c.getComponentType();
2.1839 - }
2.1840 - String baseName = c.getName();
2.1841 - int index = baseName.lastIndexOf('.');
2.1842 - if (index != -1) {
2.1843 - name = baseName.substring(0, index).replace('.', '/')
2.1844 - +"/"+name;
2.1845 - }
2.1846 - } else {
2.1847 - name = name.substring(1);
2.1848 - }
2.1849 - return name;
2.1850 - }
2.1851 -
2.1852 - /**
2.1853 - * Reflection support.
2.1854 - */
2.1855 -
2.1856 - // Caches for certain reflective results
2.1857 - private static boolean useCaches = true;
2.1858 - private volatile transient SoftReference<Field[]> declaredFields;
2.1859 - private volatile transient SoftReference<Field[]> publicFields;
2.1860 - private volatile transient SoftReference<Method[]> declaredMethods;
2.1861 - private volatile transient SoftReference<Method[]> publicMethods;
2.1862 - private volatile transient SoftReference<Constructor<T>[]> declaredConstructors;
2.1863 - private volatile transient SoftReference<Constructor<T>[]> publicConstructors;
2.1864 - // Intermediate results for getFields and getMethods
2.1865 - private volatile transient SoftReference<Field[]> declaredPublicFields;
2.1866 - private volatile transient SoftReference<Method[]> declaredPublicMethods;
2.1867 -
2.1868 - // Incremented by the VM on each call to JVM TI RedefineClasses()
2.1869 - // that redefines this class or a superclass.
2.1870 - private volatile transient int classRedefinedCount = 0;
2.1871 -
2.1872 - // Value of classRedefinedCount when we last cleared the cached values
2.1873 - // that are sensitive to class redefinition.
2.1874 - private volatile transient int lastRedefinedCount = 0;
2.1875 -
2.1876 - // Clears cached values that might possibly have been obsoleted by
2.1877 - // a class redefinition.
2.1878 - private void clearCachesOnClassRedefinition() {
2.1879 - if (lastRedefinedCount != classRedefinedCount) {
2.1880 - declaredFields = publicFields = declaredPublicFields = null;
2.1881 - declaredMethods = publicMethods = declaredPublicMethods = null;
2.1882 - declaredConstructors = publicConstructors = null;
2.1883 - annotations = declaredAnnotations = null;
2.1884 -
2.1885 - // Use of "volatile" (and synchronization by caller in the case
2.1886 - // of annotations) ensures that no thread sees the update to
2.1887 - // lastRedefinedCount before seeing the caches cleared.
2.1888 - // We do not guard against brief windows during which multiple
2.1889 - // threads might redundantly work to fill an empty cache.
2.1890 - lastRedefinedCount = classRedefinedCount;
2.1891 - }
2.1892 - }
2.1893 -
2.1894 - // Generic signature handling
2.1895 - private native String getGenericSignature();
2.1896 -
2.1897 - // Generic info repository; lazily initialized
2.1898 - private transient ClassRepository genericInfo;
2.1899 -
2.1900 - // accessor for factory
2.1901 - private GenericsFactory getFactory() {
2.1902 - // create scope and factory
2.1903 - return CoreReflectionFactory.make(this, ClassScope.make(this));
2.1904 - }
2.1905 -
2.1906 - // accessor for generic info repository
2.1907 - private ClassRepository getGenericInfo() {
2.1908 - // lazily initialize repository if necessary
2.1909 - if (genericInfo == null) {
2.1910 - // create and cache generic info repository
2.1911 - genericInfo = ClassRepository.make(getGenericSignature(),
2.1912 - getFactory());
2.1913 - }
2.1914 - return genericInfo; //return cached repository
2.1915 - }
2.1916 -
2.1917 - // Annotations handling
2.1918 - private native byte[] getRawAnnotations();
2.1919 -
2.1920 - native ConstantPool getConstantPool();
2.1921 -
2.1922 - //
2.1923 - //
2.1924 - // java.lang.reflect.Field handling
2.1925 - //
2.1926 - //
2.1927 -
2.1928 - // Returns an array of "root" fields. These Field objects must NOT
2.1929 - // be propagated to the outside world, but must instead be copied
2.1930 - // via ReflectionFactory.copyField.
2.1931 - private Field[] privateGetDeclaredFields(boolean publicOnly) {
2.1932 - checkInitted();
2.1933 - Field[] res = null;
2.1934 - if (useCaches) {
2.1935 - clearCachesOnClassRedefinition();
2.1936 - if (publicOnly) {
2.1937 - if (declaredPublicFields != null) {
2.1938 - res = declaredPublicFields.get();
2.1939 - }
2.1940 - } else {
2.1941 - if (declaredFields != null) {
2.1942 - res = declaredFields.get();
2.1943 - }
2.1944 - }
2.1945 - if (res != null) return res;
2.1946 - }
2.1947 - // No cached value available; request value from VM
2.1948 - res = Reflection.filterFields(this, getDeclaredFields0(publicOnly));
2.1949 - if (useCaches) {
2.1950 - if (publicOnly) {
2.1951 - declaredPublicFields = new SoftReference<>(res);
2.1952 - } else {
2.1953 - declaredFields = new SoftReference<>(res);
2.1954 - }
2.1955 - }
2.1956 - return res;
2.1957 - }
2.1958 -
2.1959 - // Returns an array of "root" fields. These Field objects must NOT
2.1960 - // be propagated to the outside world, but must instead be copied
2.1961 - // via ReflectionFactory.copyField.
2.1962 - private Field[] privateGetPublicFields(Set<Class<?>> traversedInterfaces) {
2.1963 - checkInitted();
2.1964 - Field[] res = null;
2.1965 - if (useCaches) {
2.1966 - clearCachesOnClassRedefinition();
2.1967 - if (publicFields != null) {
2.1968 - res = publicFields.get();
2.1969 - }
2.1970 - if (res != null) return res;
2.1971 - }
2.1972 -
2.1973 - // No cached value available; compute value recursively.
2.1974 - // Traverse in correct order for getField().
2.1975 - List<Field> fields = new ArrayList<>();
2.1976 - if (traversedInterfaces == null) {
2.1977 - traversedInterfaces = new HashSet<>();
2.1978 - }
2.1979 -
2.1980 - // Local fields
2.1981 - Field[] tmp = privateGetDeclaredFields(true);
2.1982 - addAll(fields, tmp);
2.1983 -
2.1984 - // Direct superinterfaces, recursively
2.1985 - for (Class<?> c : getInterfaces()) {
2.1986 - if (!traversedInterfaces.contains(c)) {
2.1987 - traversedInterfaces.add(c);
2.1988 - addAll(fields, c.privateGetPublicFields(traversedInterfaces));
2.1989 - }
2.1990 - }
2.1991 -
2.1992 - // Direct superclass, recursively
2.1993 - if (!isInterface()) {
2.1994 - Class<?> c = getSuperclass();
2.1995 - if (c != null) {
2.1996 - addAll(fields, c.privateGetPublicFields(traversedInterfaces));
2.1997 - }
2.1998 - }
2.1999 -
2.2000 - res = new Field[fields.size()];
2.2001 - fields.toArray(res);
2.2002 - if (useCaches) {
2.2003 - publicFields = new SoftReference<>(res);
2.2004 - }
2.2005 - return res;
2.2006 - }
2.2007 -
2.2008 - private static void addAll(Collection<Field> c, Field[] o) {
2.2009 - for (int i = 0; i < o.length; i++) {
2.2010 - c.add(o[i]);
2.2011 - }
2.2012 - }
2.2013 -
2.2014 -
2.2015 - //
2.2016 - //
2.2017 - // java.lang.reflect.Constructor handling
2.2018 - //
2.2019 - //
2.2020 -
2.2021 - // Returns an array of "root" constructors. These Constructor
2.2022 - // objects must NOT be propagated to the outside world, but must
2.2023 - // instead be copied via ReflectionFactory.copyConstructor.
2.2024 - private Constructor<T>[] privateGetDeclaredConstructors(boolean publicOnly) {
2.2025 - checkInitted();
2.2026 - Constructor<T>[] res = null;
2.2027 - if (useCaches) {
2.2028 - clearCachesOnClassRedefinition();
2.2029 - if (publicOnly) {
2.2030 - if (publicConstructors != null) {
2.2031 - res = publicConstructors.get();
2.2032 - }
2.2033 - } else {
2.2034 - if (declaredConstructors != null) {
2.2035 - res = declaredConstructors.get();
2.2036 - }
2.2037 - }
2.2038 - if (res != null) return res;
2.2039 - }
2.2040 - // No cached value available; request value from VM
2.2041 - if (isInterface()) {
2.2042 - res = new Constructor[0];
2.2043 - } else {
2.2044 - res = getDeclaredConstructors0(publicOnly);
2.2045 - }
2.2046 - if (useCaches) {
2.2047 - if (publicOnly) {
2.2048 - publicConstructors = new SoftReference<>(res);
2.2049 - } else {
2.2050 - declaredConstructors = new SoftReference<>(res);
2.2051 - }
2.2052 - }
2.2053 - return res;
2.2054 - }
2.2055 -
2.2056 - //
2.2057 - //
2.2058 - // java.lang.reflect.Method handling
2.2059 - //
2.2060 - //
2.2061 -
2.2062 - // Returns an array of "root" methods. These Method objects must NOT
2.2063 - // be propagated to the outside world, but must instead be copied
2.2064 - // via ReflectionFactory.copyMethod.
2.2065 - private Method[] privateGetDeclaredMethods(boolean publicOnly) {
2.2066 - checkInitted();
2.2067 - Method[] res = null;
2.2068 - if (useCaches) {
2.2069 - clearCachesOnClassRedefinition();
2.2070 - if (publicOnly) {
2.2071 - if (declaredPublicMethods != null) {
2.2072 - res = declaredPublicMethods.get();
2.2073 - }
2.2074 - } else {
2.2075 - if (declaredMethods != null) {
2.2076 - res = declaredMethods.get();
2.2077 - }
2.2078 - }
2.2079 - if (res != null) return res;
2.2080 - }
2.2081 - // No cached value available; request value from VM
2.2082 - res = Reflection.filterMethods(this, getDeclaredMethods0(publicOnly));
2.2083 - if (useCaches) {
2.2084 - if (publicOnly) {
2.2085 - declaredPublicMethods = new SoftReference<>(res);
2.2086 - } else {
2.2087 - declaredMethods = new SoftReference<>(res);
2.2088 - }
2.2089 - }
2.2090 - return res;
2.2091 - }
2.2092 -
2.2093 - static class MethodArray {
2.2094 - private Method[] methods;
2.2095 - private int length;
2.2096 -
2.2097 - MethodArray() {
2.2098 - methods = new Method[20];
2.2099 - length = 0;
2.2100 - }
2.2101 -
2.2102 - void add(Method m) {
2.2103 - if (length == methods.length) {
2.2104 - methods = Arrays.copyOf(methods, 2 * methods.length);
2.2105 - }
2.2106 - methods[length++] = m;
2.2107 - }
2.2108 -
2.2109 - void addAll(Method[] ma) {
2.2110 - for (int i = 0; i < ma.length; i++) {
2.2111 - add(ma[i]);
2.2112 - }
2.2113 - }
2.2114 -
2.2115 - void addAll(MethodArray ma) {
2.2116 - for (int i = 0; i < ma.length(); i++) {
2.2117 - add(ma.get(i));
2.2118 - }
2.2119 - }
2.2120 -
2.2121 - void addIfNotPresent(Method newMethod) {
2.2122 - for (int i = 0; i < length; i++) {
2.2123 - Method m = methods[i];
2.2124 - if (m == newMethod || (m != null && m.equals(newMethod))) {
2.2125 - return;
2.2126 - }
2.2127 - }
2.2128 - add(newMethod);
2.2129 - }
2.2130 -
2.2131 - void addAllIfNotPresent(MethodArray newMethods) {
2.2132 - for (int i = 0; i < newMethods.length(); i++) {
2.2133 - Method m = newMethods.get(i);
2.2134 - if (m != null) {
2.2135 - addIfNotPresent(m);
2.2136 - }
2.2137 - }
2.2138 - }
2.2139 -
2.2140 - int length() {
2.2141 - return length;
2.2142 - }
2.2143 -
2.2144 - Method get(int i) {
2.2145 - return methods[i];
2.2146 - }
2.2147 -
2.2148 - void removeByNameAndSignature(Method toRemove) {
2.2149 - for (int i = 0; i < length; i++) {
2.2150 - Method m = methods[i];
2.2151 - if (m != null &&
2.2152 - m.getReturnType() == toRemove.getReturnType() &&
2.2153 - m.getName() == toRemove.getName() &&
2.2154 - arrayContentsEq(m.getParameterTypes(),
2.2155 - toRemove.getParameterTypes())) {
2.2156 - methods[i] = null;
2.2157 - }
2.2158 - }
2.2159 - }
2.2160 -
2.2161 - void compactAndTrim() {
2.2162 - int newPos = 0;
2.2163 - // Get rid of null slots
2.2164 - for (int pos = 0; pos < length; pos++) {
2.2165 - Method m = methods[pos];
2.2166 - if (m != null) {
2.2167 - if (pos != newPos) {
2.2168 - methods[newPos] = m;
2.2169 - }
2.2170 - newPos++;
2.2171 - }
2.2172 - }
2.2173 - if (newPos != methods.length) {
2.2174 - methods = Arrays.copyOf(methods, newPos);
2.2175 - }
2.2176 - }
2.2177 -
2.2178 - Method[] getArray() {
2.2179 - return methods;
2.2180 - }
2.2181 - }
2.2182 -
2.2183 -
2.2184 - // Returns an array of "root" methods. These Method objects must NOT
2.2185 - // be propagated to the outside world, but must instead be copied
2.2186 - // via ReflectionFactory.copyMethod.
2.2187 - private Method[] privateGetPublicMethods() {
2.2188 - checkInitted();
2.2189 - Method[] res = null;
2.2190 - if (useCaches) {
2.2191 - clearCachesOnClassRedefinition();
2.2192 - if (publicMethods != null) {
2.2193 - res = publicMethods.get();
2.2194 - }
2.2195 - if (res != null) return res;
2.2196 - }
2.2197 -
2.2198 - // No cached value available; compute value recursively.
2.2199 - // Start by fetching public declared methods
2.2200 - MethodArray methods = new MethodArray();
2.2201 - {
2.2202 - Method[] tmp = privateGetDeclaredMethods(true);
2.2203 - methods.addAll(tmp);
2.2204 - }
2.2205 - // Now recur over superclass and direct superinterfaces.
2.2206 - // Go over superinterfaces first so we can more easily filter
2.2207 - // out concrete implementations inherited from superclasses at
2.2208 - // the end.
2.2209 - MethodArray inheritedMethods = new MethodArray();
2.2210 - Class<?>[] interfaces = getInterfaces();
2.2211 - for (int i = 0; i < interfaces.length; i++) {
2.2212 - inheritedMethods.addAll(interfaces[i].privateGetPublicMethods());
2.2213 - }
2.2214 - if (!isInterface()) {
2.2215 - Class<?> c = getSuperclass();
2.2216 - if (c != null) {
2.2217 - MethodArray supers = new MethodArray();
2.2218 - supers.addAll(c.privateGetPublicMethods());
2.2219 - // Filter out concrete implementations of any
2.2220 - // interface methods
2.2221 - for (int i = 0; i < supers.length(); i++) {
2.2222 - Method m = supers.get(i);
2.2223 - if (m != null && !Modifier.isAbstract(m.getModifiers())) {
2.2224 - inheritedMethods.removeByNameAndSignature(m);
2.2225 - }
2.2226 - }
2.2227 - // Insert superclass's inherited methods before
2.2228 - // superinterfaces' to satisfy getMethod's search
2.2229 - // order
2.2230 - supers.addAll(inheritedMethods);
2.2231 - inheritedMethods = supers;
2.2232 - }
2.2233 - }
2.2234 - // Filter out all local methods from inherited ones
2.2235 - for (int i = 0; i < methods.length(); i++) {
2.2236 - Method m = methods.get(i);
2.2237 - inheritedMethods.removeByNameAndSignature(m);
2.2238 - }
2.2239 - methods.addAllIfNotPresent(inheritedMethods);
2.2240 - methods.compactAndTrim();
2.2241 - res = methods.getArray();
2.2242 - if (useCaches) {
2.2243 - publicMethods = new SoftReference<>(res);
2.2244 - }
2.2245 - return res;
2.2246 - }
2.2247 -
2.2248 -
2.2249 - //
2.2250 - // Helpers for fetchers of one field, method, or constructor
2.2251 - //
2.2252 -
2.2253 - private Field searchFields(Field[] fields, String name) {
2.2254 - String internedName = name.intern();
2.2255 - for (int i = 0; i < fields.length; i++) {
2.2256 - if (fields[i].getName() == internedName) {
2.2257 - return getReflectionFactory().copyField(fields[i]);
2.2258 - }
2.2259 - }
2.2260 - return null;
2.2261 - }
2.2262 -
2.2263 - private Field getField0(String name) throws NoSuchFieldException {
2.2264 - // Note: the intent is that the search algorithm this routine
2.2265 - // uses be equivalent to the ordering imposed by
2.2266 - // privateGetPublicFields(). It fetches only the declared
2.2267 - // public fields for each class, however, to reduce the number
2.2268 - // of Field objects which have to be created for the common
2.2269 - // case where the field being requested is declared in the
2.2270 - // class which is being queried.
2.2271 - Field res = null;
2.2272 - // Search declared public fields
2.2273 - if ((res = searchFields(privateGetDeclaredFields(true), name)) != null) {
2.2274 - return res;
2.2275 - }
2.2276 - // Direct superinterfaces, recursively
2.2277 - Class<?>[] interfaces = getInterfaces();
2.2278 - for (int i = 0; i < interfaces.length; i++) {
2.2279 - Class<?> c = interfaces[i];
2.2280 - if ((res = c.getField0(name)) != null) {
2.2281 - return res;
2.2282 - }
2.2283 - }
2.2284 - // Direct superclass, recursively
2.2285 - if (!isInterface()) {
2.2286 - Class<?> c = getSuperclass();
2.2287 - if (c != null) {
2.2288 - if ((res = c.getField0(name)) != null) {
2.2289 - return res;
2.2290 - }
2.2291 - }
2.2292 - }
2.2293 - return null;
2.2294 - }
2.2295 -
2.2296 - private static Method searchMethods(Method[] methods,
2.2297 - String name,
2.2298 - Class<?>[] parameterTypes)
2.2299 - {
2.2300 - Method res = null;
2.2301 - String internedName = name.intern();
2.2302 - for (int i = 0; i < methods.length; i++) {
2.2303 - Method m = methods[i];
2.2304 - if (m.getName() == internedName
2.2305 - && arrayContentsEq(parameterTypes, m.getParameterTypes())
2.2306 - && (res == null
2.2307 - || res.getReturnType().isAssignableFrom(m.getReturnType())))
2.2308 - res = m;
2.2309 - }
2.2310 -
2.2311 - return (res == null ? res : getReflectionFactory().copyMethod(res));
2.2312 - }
2.2313 -
2.2314 -
2.2315 - private Method getMethod0(String name, Class<?>[] parameterTypes) {
2.2316 - // Note: the intent is that the search algorithm this routine
2.2317 - // uses be equivalent to the ordering imposed by
2.2318 - // privateGetPublicMethods(). It fetches only the declared
2.2319 - // public methods for each class, however, to reduce the
2.2320 - // number of Method objects which have to be created for the
2.2321 - // common case where the method being requested is declared in
2.2322 - // the class which is being queried.
2.2323 - Method res = null;
2.2324 - // Search declared public methods
2.2325 - if ((res = searchMethods(privateGetDeclaredMethods(true),
2.2326 - name,
2.2327 - parameterTypes)) != null) {
2.2328 - return res;
2.2329 - }
2.2330 - // Search superclass's methods
2.2331 - if (!isInterface()) {
2.2332 - Class<? super T> c = getSuperclass();
2.2333 - if (c != null) {
2.2334 - if ((res = c.getMethod0(name, parameterTypes)) != null) {
2.2335 - return res;
2.2336 - }
2.2337 - }
2.2338 - }
2.2339 - // Search superinterfaces' methods
2.2340 - Class<?>[] interfaces = getInterfaces();
2.2341 - for (int i = 0; i < interfaces.length; i++) {
2.2342 - Class<?> c = interfaces[i];
2.2343 - if ((res = c.getMethod0(name, parameterTypes)) != null) {
2.2344 - return res;
2.2345 - }
2.2346 - }
2.2347 - // Not found
2.2348 - return null;
2.2349 - }
2.2350 -
2.2351 - private Constructor<T> getConstructor0(Class<?>[] parameterTypes,
2.2352 - int which) throws NoSuchMethodException
2.2353 - {
2.2354 - Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
2.2355 - for (Constructor<T> constructor : constructors) {
2.2356 - if (arrayContentsEq(parameterTypes,
2.2357 - constructor.getParameterTypes())) {
2.2358 - return getReflectionFactory().copyConstructor(constructor);
2.2359 - }
2.2360 - }
2.2361 - throw new NoSuchMethodException(getName() + ".<init>" + argumentTypesToString(parameterTypes));
2.2362 - }
2.2363 -
2.2364 - //
2.2365 - // Other helpers and base implementation
2.2366 - //
2.2367 -
2.2368 - private static boolean arrayContentsEq(Object[] a1, Object[] a2) {
2.2369 - if (a1 == null) {
2.2370 - return a2 == null || a2.length == 0;
2.2371 - }
2.2372 -
2.2373 - if (a2 == null) {
2.2374 - return a1.length == 0;
2.2375 - }
2.2376 -
2.2377 - if (a1.length != a2.length) {
2.2378 - return false;
2.2379 - }
2.2380 -
2.2381 - for (int i = 0; i < a1.length; i++) {
2.2382 - if (a1[i] != a2[i]) {
2.2383 - return false;
2.2384 - }
2.2385 - }
2.2386 -
2.2387 - return true;
2.2388 - }
2.2389 -
2.2390 - private static Field[] copyFields(Field[] arg) {
2.2391 - Field[] out = new Field[arg.length];
2.2392 - ReflectionFactory fact = getReflectionFactory();
2.2393 - for (int i = 0; i < arg.length; i++) {
2.2394 - out[i] = fact.copyField(arg[i]);
2.2395 - }
2.2396 - return out;
2.2397 - }
2.2398 -
2.2399 - private static Method[] copyMethods(Method[] arg) {
2.2400 - Method[] out = new Method[arg.length];
2.2401 - ReflectionFactory fact = getReflectionFactory();
2.2402 - for (int i = 0; i < arg.length; i++) {
2.2403 - out[i] = fact.copyMethod(arg[i]);
2.2404 - }
2.2405 - return out;
2.2406 - }
2.2407 -
2.2408 - private static <U> Constructor<U>[] copyConstructors(Constructor<U>[] arg) {
2.2409 - Constructor<U>[] out = arg.clone();
2.2410 - ReflectionFactory fact = getReflectionFactory();
2.2411 - for (int i = 0; i < out.length; i++) {
2.2412 - out[i] = fact.copyConstructor(out[i]);
2.2413 - }
2.2414 - return out;
2.2415 - }
2.2416 -
2.2417 - private native Field[] getDeclaredFields0(boolean publicOnly);
2.2418 - private native Method[] getDeclaredMethods0(boolean publicOnly);
2.2419 - private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
2.2420 - private native Class<?>[] getDeclaredClasses0();
2.2421 -
2.2422 - private static String argumentTypesToString(Class<?>[] argTypes) {
2.2423 - StringBuilder buf = new StringBuilder();
2.2424 - buf.append("(");
2.2425 - if (argTypes != null) {
2.2426 - for (int i = 0; i < argTypes.length; i++) {
2.2427 - if (i > 0) {
2.2428 - buf.append(", ");
2.2429 - }
2.2430 - Class<?> c = argTypes[i];
2.2431 - buf.append((c == null) ? "null" : c.getName());
2.2432 - }
2.2433 - }
2.2434 - buf.append(")");
2.2435 - return buf.toString();
2.2436 - }
2.2437 -
2.2438 - /** use serialVersionUID from JDK 1.1 for interoperability */
2.2439 - private static final long serialVersionUID = 3206093459760846163L;
2.2440 -
2.2441 -
2.2442 - /**
2.2443 - * Class Class is special cased within the Serialization Stream Protocol.
2.2444 - *
2.2445 - * A Class instance is written initially into an ObjectOutputStream in the
2.2446 - * following format:
2.2447 - * <pre>
2.2448 - * {@code TC_CLASS} ClassDescriptor
2.2449 - * A ClassDescriptor is a special cased serialization of
2.2450 - * a {@code java.io.ObjectStreamClass} instance.
2.2451 - * </pre>
2.2452 - * A new handle is generated for the initial time the class descriptor
2.2453 - * is written into the stream. Future references to the class descriptor
2.2454 - * are written as references to the initial class descriptor instance.
2.2455 - *
2.2456 - * @see java.io.ObjectStreamClass
2.2457 - */
2.2458 - private static final ObjectStreamField[] serialPersistentFields =
2.2459 - new ObjectStreamField[0];
2.2460 -
2.2461 -
2.2462 - /**
2.2463 - * Returns the assertion status that would be assigned to this
2.2464 - * class if it were to be initialized at the time this method is invoked.
2.2465 - * If this class has had its assertion status set, the most recent
2.2466 - * setting will be returned; otherwise, if any package default assertion
2.2467 - * status pertains to this class, the most recent setting for the most
2.2468 - * specific pertinent package default assertion status is returned;
2.2469 - * otherwise, if this class is not a system class (i.e., it has a
2.2470 - * class loader) its class loader's default assertion status is returned;
2.2471 - * otherwise, the system class default assertion status is returned.
2.2472 - * <p>
2.2473 - * Few programmers will have any need for this method; it is provided
2.2474 - * for the benefit of the JRE itself. (It allows a class to determine at
2.2475 - * the time that it is initialized whether assertions should be enabled.)
2.2476 - * Note that this method is not guaranteed to return the actual
2.2477 - * assertion status that was (or will be) associated with the specified
2.2478 - * class when it was (or will be) initialized.
2.2479 - *
2.2480 - * @return the desired assertion status of the specified class.
2.2481 - * @see java.lang.ClassLoader#setClassAssertionStatus
2.2482 - * @see java.lang.ClassLoader#setPackageAssertionStatus
2.2483 - * @see java.lang.ClassLoader#setDefaultAssertionStatus
2.2484 - * @since 1.4
2.2485 - */
2.2486 - public boolean desiredAssertionStatus() {
2.2487 - ClassLoader loader = getClassLoader();
2.2488 - // If the loader is null this is a system class, so ask the VM
2.2489 - if (loader == null)
2.2490 - return desiredAssertionStatus0(this);
2.2491 -
2.2492 - // If the classloader has been initialized with the assertion
2.2493 - // directives, ask it. Otherwise, ask the VM.
2.2494 - synchronized(loader.assertionLock) {
2.2495 - if (loader.classAssertionStatus != null) {
2.2496 - return loader.desiredAssertionStatus(getName());
2.2497 - }
2.2498 - }
2.2499 - return desiredAssertionStatus0(this);
2.2500 - }
2.2501 -
2.2502 - // Retrieves the desired assertion status of this class from the VM
2.2503 - private static native boolean desiredAssertionStatus0(Class<?> clazz);
2.2504
2.2505 /**
2.2506 * Returns true if and only if this class was declared as an enum in the
2.2507 @@ -2878,116 +625,6 @@
2.2508 this.getSuperclass() == java.lang.Enum.class;
2.2509 }
2.2510
2.2511 - // Fetches the factory for reflective objects
2.2512 - private static ReflectionFactory getReflectionFactory() {
2.2513 - if (reflectionFactory == null) {
2.2514 - reflectionFactory =
2.2515 - java.security.AccessController.doPrivileged
2.2516 - (new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
2.2517 - }
2.2518 - return reflectionFactory;
2.2519 - }
2.2520 - private static ReflectionFactory reflectionFactory;
2.2521 -
2.2522 - // To be able to query system properties as soon as they're available
2.2523 - private static boolean initted = false;
2.2524 - private static void checkInitted() {
2.2525 - if (initted) return;
2.2526 - AccessController.doPrivileged(new PrivilegedAction<Void>() {
2.2527 - public Void run() {
2.2528 - // Tests to ensure the system properties table is fully
2.2529 - // initialized. This is needed because reflection code is
2.2530 - // called very early in the initialization process (before
2.2531 - // command-line arguments have been parsed and therefore
2.2532 - // these user-settable properties installed.) We assume that
2.2533 - // if System.out is non-null then the System class has been
2.2534 - // fully initialized and that the bulk of the startup code
2.2535 - // has been run.
2.2536 -
2.2537 - if (System.out == null) {
2.2538 - // java.lang.System not yet fully initialized
2.2539 - return null;
2.2540 - }
2.2541 -
2.2542 - String val =
2.2543 - System.getProperty("sun.reflect.noCaches");
2.2544 - if (val != null && val.equals("true")) {
2.2545 - useCaches = false;
2.2546 - }
2.2547 -
2.2548 - initted = true;
2.2549 - return null;
2.2550 - }
2.2551 - });
2.2552 - }
2.2553 -
2.2554 - /**
2.2555 - * Returns the elements of this enum class or null if this
2.2556 - * Class object does not represent an enum type.
2.2557 - *
2.2558 - * @return an array containing the values comprising the enum class
2.2559 - * represented by this Class object in the order they're
2.2560 - * declared, or null if this Class object does not
2.2561 - * represent an enum type
2.2562 - * @since 1.5
2.2563 - */
2.2564 - public T[] getEnumConstants() {
2.2565 - T[] values = getEnumConstantsShared();
2.2566 - return (values != null) ? values.clone() : null;
2.2567 - }
2.2568 -
2.2569 - /**
2.2570 - * Returns the elements of this enum class or null if this
2.2571 - * Class object does not represent an enum type;
2.2572 - * identical to getEnumConstants except that the result is
2.2573 - * uncloned, cached, and shared by all callers.
2.2574 - */
2.2575 - T[] getEnumConstantsShared() {
2.2576 - if (enumConstants == null) {
2.2577 - if (!isEnum()) return null;
2.2578 - try {
2.2579 - final Method values = getMethod("values");
2.2580 - java.security.AccessController.doPrivileged(
2.2581 - new java.security.PrivilegedAction<Void>() {
2.2582 - public Void run() {
2.2583 - values.setAccessible(true);
2.2584 - return null;
2.2585 - }
2.2586 - });
2.2587 - enumConstants = (T[])values.invoke(null);
2.2588 - }
2.2589 - // These can happen when users concoct enum-like classes
2.2590 - // that don't comply with the enum spec.
2.2591 - catch (InvocationTargetException ex) { return null; }
2.2592 - catch (NoSuchMethodException ex) { return null; }
2.2593 - catch (IllegalAccessException ex) { return null; }
2.2594 - }
2.2595 - return enumConstants;
2.2596 - }
2.2597 - private volatile transient T[] enumConstants = null;
2.2598 -
2.2599 - /**
2.2600 - * Returns a map from simple name to enum constant. This package-private
2.2601 - * method is used internally by Enum to implement
2.2602 - * public static <T extends Enum<T>> T valueOf(Class<T>, String)
2.2603 - * efficiently. Note that the map is returned by this method is
2.2604 - * created lazily on first use. Typically it won't ever get created.
2.2605 - */
2.2606 - Map<String, T> enumConstantDirectory() {
2.2607 - if (enumConstantDirectory == null) {
2.2608 - T[] universe = getEnumConstantsShared();
2.2609 - if (universe == null)
2.2610 - throw new IllegalArgumentException(
2.2611 - getName() + " is not an enum type");
2.2612 - Map<String, T> m = new HashMap<>(2 * universe.length);
2.2613 - for (T constant : universe)
2.2614 - m.put(((Enum<?>)constant).name(), constant);
2.2615 - enumConstantDirectory = m;
2.2616 - }
2.2617 - return enumConstantDirectory;
2.2618 - }
2.2619 - private volatile transient Map<String, T> enumConstantDirectory = null;
2.2620 -
2.2621 /**
2.2622 * Casts an object to the class or interface represented
2.2623 * by this {@code Class} object.
2.2624 @@ -3042,11 +679,7 @@
2.2625 * @since 1.5
2.2626 */
2.2627 public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
2.2628 - if (annotationClass == null)
2.2629 - throw new NullPointerException();
2.2630 -
2.2631 - initAnnotationsIfNecessary();
2.2632 - return (A) annotations.get(annotationClass);
2.2633 + throw new UnsupportedOperationException();
2.2634 }
2.2635
2.2636 /**
2.2637 @@ -3066,52 +699,14 @@
2.2638 * @since 1.5
2.2639 */
2.2640 public Annotation[] getAnnotations() {
2.2641 - initAnnotationsIfNecessary();
2.2642 - return AnnotationParser.toArray(annotations);
2.2643 + throw new UnsupportedOperationException();
2.2644 }
2.2645
2.2646 /**
2.2647 * @since 1.5
2.2648 */
2.2649 public Annotation[] getDeclaredAnnotations() {
2.2650 - initAnnotationsIfNecessary();
2.2651 - return AnnotationParser.toArray(declaredAnnotations);
2.2652 + throw new UnsupportedOperationException();
2.2653 }
2.2654
2.2655 - // Annotations cache
2.2656 - private transient Map<Class<? extends Annotation>, Annotation> annotations;
2.2657 - private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
2.2658 -
2.2659 - private synchronized void initAnnotationsIfNecessary() {
2.2660 - clearCachesOnClassRedefinition();
2.2661 - if (annotations != null)
2.2662 - return;
2.2663 - declaredAnnotations = AnnotationParser.parseAnnotations(
2.2664 - getRawAnnotations(), getConstantPool(), this);
2.2665 - Class<?> superClass = getSuperclass();
2.2666 - if (superClass == null) {
2.2667 - annotations = declaredAnnotations;
2.2668 - } else {
2.2669 - annotations = new HashMap<>();
2.2670 - superClass.initAnnotationsIfNecessary();
2.2671 - for (Map.Entry<Class<? extends Annotation>, Annotation> e : superClass.annotations.entrySet()) {
2.2672 - Class<? extends Annotation> annotationClass = e.getKey();
2.2673 - if (AnnotationType.getInstance(annotationClass).isInherited())
2.2674 - annotations.put(annotationClass, e.getValue());
2.2675 - }
2.2676 - annotations.putAll(declaredAnnotations);
2.2677 - }
2.2678 - }
2.2679 -
2.2680 - // Annotation types cache their internal (AnnotationType) form
2.2681 -
2.2682 - private AnnotationType annotationType;
2.2683 -
2.2684 - void setAnnotationType(AnnotationType type) {
2.2685 - annotationType = type;
2.2686 - }
2.2687 -
2.2688 - AnnotationType getAnnotationType() {
2.2689 - return annotationType;
2.2690 - }
2.2691 }
3.1 --- a/emul/src/main/java/java/lang/StackTraceElement.java Sat Sep 29 08:26:30 2012 +0200
3.2 +++ b/emul/src/main/java/java/lang/StackTraceElement.java Sat Sep 29 10:47:42 2012 +0200
3.3 @@ -25,8 +25,6 @@
3.4
3.5 package java.lang;
3.6
3.7 -import java.util.Objects;
3.8 -
3.9 /**
3.10 * An element in a stack trace, as returned by {@link
3.11 * Throwable#getStackTrace()}. Each element represents a single stack frame.
3.12 @@ -68,8 +66,8 @@
3.13 */
3.14 public StackTraceElement(String declaringClass, String methodName,
3.15 String fileName, int lineNumber) {
3.16 - this.declaringClass = Objects.requireNonNull(declaringClass, "Declaring class is null");
3.17 - this.methodName = Objects.requireNonNull(methodName, "Method name is null");
3.18 + this.declaringClass = declaringClass;
3.19 + this.methodName = methodName;
3.20 this.fileName = fileName;
3.21 this.lineNumber = lineNumber;
3.22 }
3.23 @@ -203,8 +201,8 @@
3.24 StackTraceElement e = (StackTraceElement)obj;
3.25 return e.declaringClass.equals(declaringClass) &&
3.26 e.lineNumber == lineNumber &&
3.27 - Objects.equals(methodName, e.methodName) &&
3.28 - Objects.equals(fileName, e.fileName);
3.29 + equals(methodName, e.methodName) &&
3.30 + equals(fileName, e.fileName);
3.31 }
3.32
3.33 /**
3.34 @@ -212,10 +210,14 @@
3.35 */
3.36 public int hashCode() {
3.37 int result = 31*declaringClass.hashCode() + methodName.hashCode();
3.38 - result = 31*result + Objects.hashCode(fileName);
3.39 + result = 31*result + (fileName == null ? 0 : fileName.hashCode());
3.40 result = 31*result + lineNumber;
3.41 return result;
3.42 }
3.43 +
3.44 + private static boolean equals(Object a, Object b) {
3.45 + return (a == b) || (a != null && a.equals(b));
3.46 + }
3.47
3.48 private static final long serialVersionUID = 6992337162326171013L;
3.49 }
4.1 --- a/emul/src/main/java/java/lang/String.java Sat Sep 29 08:26:30 2012 +0200
4.2 +++ b/emul/src/main/java/java/lang/String.java Sat Sep 29 10:47:42 2012 +0200
4.3 @@ -25,7 +25,6 @@
4.4
4.5 package java.lang;
4.6
4.7 -import java.io.ObjectStreamField;
4.8 import java.io.UnsupportedEncodingException;
4.9 import java.util.Comparator;
4.10
4.11 @@ -128,8 +127,8 @@
4.12 * A new handle is generated to refer to all future references to the
4.13 * string instance within the stream.
4.14 */
4.15 - private static final ObjectStreamField[] serialPersistentFields =
4.16 - new ObjectStreamField[0];
4.17 +// private static final ObjectStreamField[] serialPersistentFields =
4.18 +// new ObjectStreamField[0];
4.19
4.20 /**
4.21 * Initializes a newly created {@code String} object so that it represents
5.1 --- a/emul/src/main/java/java/lang/StringBuffer.java Sat Sep 29 08:26:30 2012 +0200
5.2 +++ b/emul/src/main/java/java/lang/StringBuffer.java Sat Sep 29 10:47:42 2012 +0200
5.3 @@ -561,45 +561,45 @@
5.4 return new String(value, 0, count);
5.5 }
5.6
5.7 - /**
5.8 - * Serializable fields for StringBuffer.
5.9 - *
5.10 - * @serialField value char[]
5.11 - * The backing character array of this StringBuffer.
5.12 - * @serialField count int
5.13 - * The number of characters in this StringBuffer.
5.14 - * @serialField shared boolean
5.15 - * A flag indicating whether the backing array is shared.
5.16 - * The value is ignored upon deserialization.
5.17 - */
5.18 - private static final java.io.ObjectStreamField[] serialPersistentFields =
5.19 - {
5.20 - new java.io.ObjectStreamField("value", char[].class),
5.21 - new java.io.ObjectStreamField("count", Integer.TYPE),
5.22 - new java.io.ObjectStreamField("shared", Boolean.TYPE),
5.23 - };
5.24 -
5.25 - /**
5.26 - * readObject is called to restore the state of the StringBuffer from
5.27 - * a stream.
5.28 - */
5.29 - private synchronized void writeObject(java.io.ObjectOutputStream s)
5.30 - throws java.io.IOException {
5.31 - java.io.ObjectOutputStream.PutField fields = s.putFields();
5.32 - fields.put("value", value);
5.33 - fields.put("count", count);
5.34 - fields.put("shared", false);
5.35 - s.writeFields();
5.36 - }
5.37 -
5.38 - /**
5.39 - * readObject is called to restore the state of the StringBuffer from
5.40 - * a stream.
5.41 - */
5.42 - private void readObject(java.io.ObjectInputStream s)
5.43 - throws java.io.IOException, ClassNotFoundException {
5.44 - java.io.ObjectInputStream.GetField fields = s.readFields();
5.45 - value = (char[])fields.get("value", null);
5.46 - count = fields.get("count", 0);
5.47 - }
5.48 +// /**
5.49 +// * Serializable fields for StringBuffer.
5.50 +// *
5.51 +// * @serialField value char[]
5.52 +// * The backing character array of this StringBuffer.
5.53 +// * @serialField count int
5.54 +// * The number of characters in this StringBuffer.
5.55 +// * @serialField shared boolean
5.56 +// * A flag indicating whether the backing array is shared.
5.57 +// * The value is ignored upon deserialization.
5.58 +// */
5.59 +// private static final java.io.ObjectStreamField[] serialPersistentFields =
5.60 +// {
5.61 +// new java.io.ObjectStreamField("value", char[].class),
5.62 +// new java.io.ObjectStreamField("count", Integer.TYPE),
5.63 +// new java.io.ObjectStreamField("shared", Boolean.TYPE),
5.64 +// };
5.65 +//
5.66 +// /**
5.67 +// * readObject is called to restore the state of the StringBuffer from
5.68 +// * a stream.
5.69 +// */
5.70 +// private synchronized void writeObject(java.io.ObjectOutputStream s)
5.71 +// throws java.io.IOException {
5.72 +// java.io.ObjectOutputStream.PutField fields = s.putFields();
5.73 +// fields.put("value", value);
5.74 +// fields.put("count", count);
5.75 +// fields.put("shared", false);
5.76 +// s.writeFields();
5.77 +// }
5.78 +//
5.79 +// /**
5.80 +// * readObject is called to restore the state of the StringBuffer from
5.81 +// * a stream.
5.82 +// */
5.83 +// private void readObject(java.io.ObjectInputStream s)
5.84 +// throws java.io.IOException, ClassNotFoundException {
5.85 +// java.io.ObjectInputStream.GetField fields = s.readFields();
5.86 +// value = (char[])fields.get("value", null);
5.87 +// count = fields.get("count", 0);
5.88 +// }
5.89 }
6.1 --- a/emul/src/main/java/java/lang/Throwable.java Sat Sep 29 08:26:30 2012 +0200
6.2 +++ b/emul/src/main/java/java/lang/Throwable.java Sat Sep 29 10:47:42 2012 +0200
6.3 @@ -905,9 +905,9 @@
6.4 * cause} field can hold; both {@code null} and {@code this} are
6.5 * valid values for the field.
6.6 */
6.7 - private void readObject(ObjectInputStream s)
6.8 - throws IOException, ClassNotFoundException {
6.9 - s.defaultReadObject(); // read in all fields
6.10 +// private void readObject(ObjectInputStream s)
6.11 +// throws IOException, ClassNotFoundException {
6.12 +// s.defaultReadObject(); // read in all fields
6.13 // if (suppressedExceptions != null) {
6.14 // List<Throwable> suppressed = null;
6.15 // if (suppressedExceptions.isEmpty()) {
6.16 @@ -927,37 +927,37 @@
6.17 // }
6.18 // suppressedExceptions = suppressed;
6.19 // } // else a null suppressedExceptions field remains null
6.20 -
6.21 - /*
6.22 - * For zero-length stack traces, use a clone of
6.23 - * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
6.24 - * allow identity comparison against UNASSIGNED_STACK in
6.25 - * getOurStackTrace. The identity of UNASSIGNED_STACK in
6.26 - * stackTrace indicates to the getOurStackTrace method that
6.27 - * the stackTrace needs to be constructed from the information
6.28 - * in backtrace.
6.29 - */
6.30 - if (stackTrace != null) {
6.31 - if (stackTrace.length == 0) {
6.32 - stackTrace = UNASSIGNED_STACK.clone();
6.33 - } else if (stackTrace.length == 1 &&
6.34 - // Check for the marker of an immutable stack trace
6.35 - SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
6.36 - stackTrace = null;
6.37 - } else { // Verify stack trace elements are non-null.
6.38 - for(StackTraceElement ste : stackTrace) {
6.39 - if (ste == null)
6.40 - throw new NullPointerException("null StackTraceElement in serial stream. ");
6.41 - }
6.42 - }
6.43 - } else {
6.44 - // A null stackTrace field in the serial form can result
6.45 - // from an exception serialized without that field in
6.46 - // older JDK releases; treat such exceptions as having
6.47 - // empty stack traces.
6.48 - stackTrace = UNASSIGNED_STACK.clone();
6.49 - }
6.50 - }
6.51 +//
6.52 +// /*
6.53 +// * For zero-length stack traces, use a clone of
6.54 +// * UNASSIGNED_STACK rather than UNASSIGNED_STACK itself to
6.55 +// * allow identity comparison against UNASSIGNED_STACK in
6.56 +// * getOurStackTrace. The identity of UNASSIGNED_STACK in
6.57 +// * stackTrace indicates to the getOurStackTrace method that
6.58 +// * the stackTrace needs to be constructed from the information
6.59 +// * in backtrace.
6.60 +// */
6.61 +// if (stackTrace != null) {
6.62 +// if (stackTrace.length == 0) {
6.63 +// stackTrace = UNASSIGNED_STACK.clone();
6.64 +// } else if (stackTrace.length == 1 &&
6.65 +// // Check for the marker of an immutable stack trace
6.66 +// SentinelHolder.STACK_TRACE_ELEMENT_SENTINEL.equals(stackTrace[0])) {
6.67 +// stackTrace = null;
6.68 +// } else { // Verify stack trace elements are non-null.
6.69 +// for(StackTraceElement ste : stackTrace) {
6.70 +// if (ste == null)
6.71 +// throw new NullPointerException("null StackTraceElement in serial stream. ");
6.72 +// }
6.73 +// }
6.74 +// } else {
6.75 +// // A null stackTrace field in the serial form can result
6.76 +// // from an exception serialized without that field in
6.77 +// // older JDK releases; treat such exceptions as having
6.78 +// // empty stack traces.
6.79 +// stackTrace = UNASSIGNED_STACK.clone();
6.80 +// }
6.81 +// }
6.82
6.83 /**
6.84 * Write a {@code Throwable} object to a stream.