fix ReflectField

This commit is contained in:
Marc Baloup 2022-07-28 02:24:25 +02:00
parent f7dc774dbd
commit 0a558c6b83
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893

View File

@ -9,6 +9,9 @@ import java.lang.reflect.Modifier;
*/ */
public final class ReflectField<T> extends ReflectMember<T, String, Field, NoSuchFieldException> { public final class ReflectField<T> extends ReflectMember<T, String, Field, NoSuchFieldException> {
/* Those fields are used to modify the value of a static variable. Depending of the current Java version,
* one of them whill be used for this purpose.
*/
private static sun.misc.Unsafe sunMiscUnsafeInstance; private static sun.misc.Unsafe sunMiscUnsafeInstance;
private static Field modifiersFieldInFieldClass; private static Field modifiersFieldInFieldClass;
static { static {
@ -24,7 +27,7 @@ public final class ReflectField<T> extends ReflectMember<T, String, Field, NoSuc
} }
try { try {
modifiersFieldInFieldClass = Reflect.ofClass(Field.class).field("modifiers").fetchFiltered(); modifiersFieldInFieldClass = Reflect.ofClass(Field.class).filteredField("modifiers").get();
} catch (Exception e) { } catch (Exception e) {
RuntimeException newEx = new RuntimeException("Cannot access " + Field.class + ".modifiers field.", e); RuntimeException newEx = new RuntimeException("Cannot access " + Field.class + ".modifiers field.", e);
if (ex != null) if (ex != null)