< prev index next >

src/java.base/share/classes/java/lang/reflect/Field.java

Print this page

        

*** 165,175 **** */ @Override @CallerSensitive public void setAccessible(boolean flag) { AccessibleObject.checkPermission(); ! if (flag) checkCanSetAccessible(Reflection.getCallerClass()); setAccessible0(flag); } @Override void checkCanSetAccessible(Class<?> caller) { --- 165,182 ---- */ @Override @CallerSensitive public void setAccessible(boolean flag) { AccessibleObject.checkPermission(); ! ! if (clazz.isInlineClass()) { ! throw new InaccessibleObjectException("cannot make a field accessible of inline class " ! + clazz.getName()); ! } ! if (flag) { ! checkCanSetAccessible(Reflection.getCallerClass()); ! } setAccessible0(flag); } @Override void checkCanSetAccessible(Class<?> caller) {
*** 771,780 **** --- 778,789 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).set(obj, value);
*** 807,816 **** --- 816,827 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setBoolean(obj, z);
*** 843,852 **** --- 854,865 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setByte(obj, b);
*** 879,888 **** --- 892,903 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setChar(Object obj, char c) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setChar(obj, c);
*** 915,924 **** --- 930,941 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setShort(Object obj, short s) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setShort(obj, s);
*** 951,960 **** --- 968,979 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setInt(obj, i);
*** 987,996 **** --- 1006,1017 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setLong(obj, l);
*** 1023,1032 **** --- 1044,1055 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setFloat(obj, f);
*** 1059,1068 **** --- 1082,1093 ---- @CallerSensitive @ForceInline // to ensure Reflection.getCallerClass optimization public void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException { + ensureNotValueClass(); + if (!override) { Class<?> caller = Reflection.getCallerClass(); checkAccess(caller, obj); } getFieldAccessor(obj).setDouble(obj, d);
*** 1075,1084 **** --- 1100,1119 ---- checkAccess(caller, clazz, Modifier.isStatic(modifiers) ? null : obj.getClass(), modifiers); } + /* + * Ensure the declaring class is not an inline class. + */ + private void ensureNotValueClass() throws IllegalAccessException { + if (clazz.isInlineClass()) { + throw new IllegalAccessException("cannot set field \"" + this + "\" of inline class " + + clazz.getName()); + } + } + // security check is done before calling this method private FieldAccessor getFieldAccessor(Object obj) throws IllegalAccessException { boolean ov = override;
< prev index next >