151 throw new IllegalArgumentException("Can not copy a non-root Field");
152
153 Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
154 res.root = this;
155 // Might as well eagerly propagate this if already present
156 res.fieldAccessor = fieldAccessor;
157 res.overrideFieldAccessor = overrideFieldAccessor;
158
159 return res;
160 }
161
162 /**
163 * @throws InaccessibleObjectException {@inheritDoc}
164 * @throws SecurityException {@inheritDoc}
165 */
166 @Override
167 @CallerSensitive
168 public void setAccessible(boolean flag) {
169 AccessibleObject.checkPermission();
170
171 if (clazz.isValue()) {
172 throw new InaccessibleObjectException("cannot make a field accessible of inline class "
173 + clazz.getName());
174 }
175 if (flag) {
176 checkCanSetAccessible(Reflection.getCallerClass());
177 }
178 setAccessible0(flag);
179 }
180
181 @Override
182 void checkCanSetAccessible(Class<?> caller) {
183 checkCanSetAccessible(caller, clazz);
184 }
185
186 /**
187 * Returns the {@code Class} object representing
188 * {@linkplain Class#asBoxType() the box type} of the class or interface
189 * that declares the field represented by this {@code Field} object.
190 */
191 @Override
192 public Class<?> getDeclaringClass() {
193 return clazz;
194 }
195
196 /**
197 * Returns the name of the field represented by this {@code Field} object.
198 */
199 public String getName() {
200 return name;
201 }
202
203 /**
204 * Returns the Java language modifiers for the field represented
205 * by this {@code Field} object, as an integer. The {@code Modifier} class should
206 * be used to decode the modifiers.
207 *
208 * @see Modifier
1090 if (!override) {
1091 Class<?> caller = Reflection.getCallerClass();
1092 checkAccess(caller, obj);
1093 }
1094 getFieldAccessor(obj).setDouble(obj, d);
1095 }
1096
1097 // check access to field
1098 private void checkAccess(Class<?> caller, Object obj)
1099 throws IllegalAccessException
1100 {
1101 checkAccess(caller, clazz,
1102 Modifier.isStatic(modifiers) ? null : obj.getClass(),
1103 modifiers);
1104 }
1105
1106 /*
1107 * Ensure the declaring class is not an inline class.
1108 */
1109 private void ensureNotValueClass() throws IllegalAccessException {
1110 if (clazz.isValue()) {
1111 throw new IllegalAccessException("cannot set field \"" + this + "\" of inline class "
1112 + clazz.getName());
1113 }
1114 }
1115
1116 // security check is done before calling this method
1117 private FieldAccessor getFieldAccessor(Object obj)
1118 throws IllegalAccessException
1119 {
1120 boolean ov = override;
1121 FieldAccessor a = (ov) ? overrideFieldAccessor : fieldAccessor;
1122 return (a != null) ? a : acquireFieldAccessor(ov);
1123 }
1124
1125 // NOTE that there is no synchronization used here. It is correct
1126 // (though not efficient) to generate more than one FieldAccessor
1127 // for a given Field. However, avoiding synchronization will
1128 // probably make the implementation more scalable.
1129 private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) {
1130 // First check to see if one has been created yet, and take it
|
151 throw new IllegalArgumentException("Can not copy a non-root Field");
152
153 Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
154 res.root = this;
155 // Might as well eagerly propagate this if already present
156 res.fieldAccessor = fieldAccessor;
157 res.overrideFieldAccessor = overrideFieldAccessor;
158
159 return res;
160 }
161
162 /**
163 * @throws InaccessibleObjectException {@inheritDoc}
164 * @throws SecurityException {@inheritDoc}
165 */
166 @Override
167 @CallerSensitive
168 public void setAccessible(boolean flag) {
169 AccessibleObject.checkPermission();
170
171 if (clazz.isInlineClass()) {
172 throw new InaccessibleObjectException("cannot make a field accessible of inline class "
173 + clazz.getName());
174 }
175 if (flag) {
176 checkCanSetAccessible(Reflection.getCallerClass());
177 }
178 setAccessible0(flag);
179 }
180
181 @Override
182 void checkCanSetAccessible(Class<?> caller) {
183 checkCanSetAccessible(caller, clazz);
184 }
185
186 /**
187 * Returns the {@code Class} object representing the class or interface
188 * that declares the field represented by this {@code Field} object.
189 */
190 @Override
191 public Class<?> getDeclaringClass() {
192 return clazz;
193 }
194
195 /**
196 * Returns the name of the field represented by this {@code Field} object.
197 */
198 public String getName() {
199 return name;
200 }
201
202 /**
203 * Returns the Java language modifiers for the field represented
204 * by this {@code Field} object, as an integer. The {@code Modifier} class should
205 * be used to decode the modifiers.
206 *
207 * @see Modifier
1089 if (!override) {
1090 Class<?> caller = Reflection.getCallerClass();
1091 checkAccess(caller, obj);
1092 }
1093 getFieldAccessor(obj).setDouble(obj, d);
1094 }
1095
1096 // check access to field
1097 private void checkAccess(Class<?> caller, Object obj)
1098 throws IllegalAccessException
1099 {
1100 checkAccess(caller, clazz,
1101 Modifier.isStatic(modifiers) ? null : obj.getClass(),
1102 modifiers);
1103 }
1104
1105 /*
1106 * Ensure the declaring class is not an inline class.
1107 */
1108 private void ensureNotValueClass() throws IllegalAccessException {
1109 if (clazz.isInlineClass()) {
1110 throw new IllegalAccessException("cannot set field \"" + this + "\" of inline class "
1111 + clazz.getName());
1112 }
1113 }
1114
1115 // security check is done before calling this method
1116 private FieldAccessor getFieldAccessor(Object obj)
1117 throws IllegalAccessException
1118 {
1119 boolean ov = override;
1120 FieldAccessor a = (ov) ? overrideFieldAccessor : fieldAccessor;
1121 return (a != null) ? a : acquireFieldAccessor(ov);
1122 }
1123
1124 // NOTE that there is no synchronization used here. It is correct
1125 // (though not efficient) to generate more than one FieldAccessor
1126 // for a given Field. However, avoiding synchronization will
1127 // probably make the implementation more scalable.
1128 private FieldAccessor acquireFieldAccessor(boolean overrideFinalCheck) {
1129 // First check to see if one has been created yet, and take it
|