1

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) return the fields, 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)?

Marcono1234
  • 5,856
  • 1
  • 25
  • 43

0 Answers0