sad because java reflection is more protected :C

This commit is contained in:
Marc Baloup 2022-07-28 02:48:19 +02:00
parent 0a558c6b83
commit c45b501ed8
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
2 changed files with 8 additions and 1 deletions

View File

@ -140,7 +140,10 @@ public class ReflectClass<T> {
* @param name the name of the field.
* @return a {@link ReflectField} wrapping the requested {@link Field}.
* @throws NoSuchFieldException if the requested field doesnt exists in the wrapped class.
* @deprecated on Java 17, does not work due to module encapsulation, it is impossible to bypass the Java reflection
* API internal filtering.
*/
@Deprecated(since = "Java 17")
public ReflectField<T> filteredField(String name) throws NoSuchFieldException {
return field0(name, true);
}

View File

@ -27,7 +27,11 @@ public final class ReflectField<T> extends ReflectMember<T, String, Field, NoSuc
}
try {
modifiersFieldInFieldClass = Reflect.ofClass(Field.class).filteredField("modifiers").get();
@SuppressWarnings("deprecation")
Field f = Runtime.version().feature() < 16
? Reflect.ofClass(Field.class).filteredField("modifiers").get()
: null;
modifiersFieldInFieldClass = f;
} catch (Exception e) {
RuntimeException newEx = new RuntimeException("Cannot access " + Field.class + ".modifiers field.", e);
if (ex != null)