62 private int slot;
63 // This is guaranteed to be interned by the VM in the 1.4
64 // reflection implementation
65 private String name;
66 private Class<?> type;
67 private int modifiers;
68 // Generics and annotations support
69 private transient String signature;
70 // generic info repository; lazily initialized
71 private transient FieldRepository genericInfo;
72 private byte[] annotations;
73 // Cached field accessor created without override
74 private FieldAccessor fieldAccessor;
75 // Cached field accessor created with override
76 private FieldAccessor overrideFieldAccessor;
77 // For sharing of FieldAccessors. This branching structure is
78 // currently only two levels deep (i.e., one root Field and
79 // potentially many Field objects pointing to it.)
80 private Field root;
81
82 // More complicated security check cache needed here than for
83 // Class.newInstance() and Constructor.newInstance()
84 private Class<?> securityCheckCache;
85 private Class<?> securityCheckTargetClassCache;
86
87 // Generics infrastructure
88
89 private String getGenericSignature() {return signature;}
90
91 // Accessor for factory
92 private GenericsFactory getFactory() {
93 Class<?> c = getDeclaringClass();
94 // create scope and factory
95 return CoreReflectionFactory.make(c, ClassScope.make(c));
96 }
97
98 // Accessor for generic info repository
99 private FieldRepository getGenericInfo() {
100 // lazily initialize repository if necessary
101 if (genericInfo == null) {
102 // create and cache generic info repository
103 genericInfo = FieldRepository.make(getGenericSignature(),
104 getFactory());
105 }
106 return genericInfo; //return cached repository
948 // Sets the FieldAccessor for this Field object and
949 // (recursively) its root
950 private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) {
951 if (overrideFinalCheck)
952 overrideFieldAccessor = accessor;
953 else
954 fieldAccessor = accessor;
955 // Propagate up
956 if (root != null) {
957 root.setFieldAccessor(accessor, overrideFinalCheck);
958 }
959 }
960
961 // NOTE: be very careful if you change the stack depth of this
962 // routine. The depth of the "getCallerClass" call is hardwired so
963 // that the compiler can have an easier time if this gets inlined.
964 private void doSecurityCheck(Object obj) throws IllegalAccessException {
965 if (!override) {
966 if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
967 Class<?> caller = Reflection.getCallerClass(4);
968 Class<?> targetClass = ((obj == null || !Modifier.isProtected(modifiers))
969 ? clazz
970 : obj.getClass());
971
972 synchronized (this) {
973 if ((securityCheckCache == caller)
974 && (securityCheckTargetClassCache == targetClass)) {
975 return;
976 }
977 }
978 Reflection.ensureMemberAccess(caller, clazz, obj, modifiers);
979 synchronized (this) {
980 securityCheckCache = caller;
981 securityCheckTargetClassCache = targetClass;
982 }
983 }
984 }
985 }
986
987 /*
988 * Utility routine to paper over array type names
989 */
990 static String getTypeName(Class<?> type) {
991 if (type.isArray()) {
992 try {
993 Class<?> cl = type;
994 int dimensions = 0;
995 while (cl.isArray()) {
996 dimensions++;
997 cl = cl.getComponentType();
998 }
999 StringBuffer sb = new StringBuffer();
1000 sb.append(cl.getName());
1001 for (int i = 0; i < dimensions; i++) {
1002 sb.append("[]");
|
62 private int slot;
63 // This is guaranteed to be interned by the VM in the 1.4
64 // reflection implementation
65 private String name;
66 private Class<?> type;
67 private int modifiers;
68 // Generics and annotations support
69 private transient String signature;
70 // generic info repository; lazily initialized
71 private transient FieldRepository genericInfo;
72 private byte[] annotations;
73 // Cached field accessor created without override
74 private FieldAccessor fieldAccessor;
75 // Cached field accessor created with override
76 private FieldAccessor overrideFieldAccessor;
77 // For sharing of FieldAccessors. This branching structure is
78 // currently only two levels deep (i.e., one root Field and
79 // potentially many Field objects pointing to it.)
80 private Field root;
81
82 // Generics infrastructure
83
84 private String getGenericSignature() {return signature;}
85
86 // Accessor for factory
87 private GenericsFactory getFactory() {
88 Class<?> c = getDeclaringClass();
89 // create scope and factory
90 return CoreReflectionFactory.make(c, ClassScope.make(c));
91 }
92
93 // Accessor for generic info repository
94 private FieldRepository getGenericInfo() {
95 // lazily initialize repository if necessary
96 if (genericInfo == null) {
97 // create and cache generic info repository
98 genericInfo = FieldRepository.make(getGenericSignature(),
99 getFactory());
100 }
101 return genericInfo; //return cached repository
943 // Sets the FieldAccessor for this Field object and
944 // (recursively) its root
945 private void setFieldAccessor(FieldAccessor accessor, boolean overrideFinalCheck) {
946 if (overrideFinalCheck)
947 overrideFieldAccessor = accessor;
948 else
949 fieldAccessor = accessor;
950 // Propagate up
951 if (root != null) {
952 root.setFieldAccessor(accessor, overrideFinalCheck);
953 }
954 }
955
956 // NOTE: be very careful if you change the stack depth of this
957 // routine. The depth of the "getCallerClass" call is hardwired so
958 // that the compiler can have an easier time if this gets inlined.
959 private void doSecurityCheck(Object obj) throws IllegalAccessException {
960 if (!override) {
961 if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
962 Class<?> caller = Reflection.getCallerClass(4);
963
964 checkAccess(caller, clazz, obj, modifiers);
965 }
966 }
967 }
968
969 /*
970 * Utility routine to paper over array type names
971 */
972 static String getTypeName(Class<?> type) {
973 if (type.isArray()) {
974 try {
975 Class<?> cl = type;
976 int dimensions = 0;
977 while (cl.isArray()) {
978 dimensions++;
979 cl = cl.getComponentType();
980 }
981 StringBuffer sb = new StringBuffer();
982 sb.append(cl.getName());
983 for (int i = 0; i < dimensions; i++) {
984 sb.append("[]");
|