mercredi 10 juin 2020

Why does java.lang.reflect.AccessibleObject.class.getDeclaredFields() not return any field anymore?

The class java.lang.reflect.AccessibleObject has multiple private fields, for example override which is present both in JDK 11 (source) and JDK 14 (source).

However, only for JDK 11 Class.getDeclaredFields() and getDeclaredField(String) returns any field, for JDK 14 (and possibly even since JDK 12) no field is returned.

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;

class AccessibleObjectTest {
    public static void main(String[] args) throws Exception {
        for (Field f : AccessibleObject.class.getDeclaredFields()) {
            System.out.println(f);
        }
    }
}

What is the reason for this?

Is there some special casing for this class because by using sun.misc.Unsafe it would otherwise easily be possible to circumvent reflective access checks (example)?





Aucun commentaire:

Enregistrer un commentaire