-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Right now, the Configuration class uses the classic reflection API of Java to inject fields, and calls setAccessible(true) to access private fields (so called deep reflection). This means for example that in modern, modularized, Java applications --add-opens needs to be used. However, there is a modern reflection API with which we can directly access private members of other classes if these other classes allow us to, which fits our use case.
So we should migrate to this new API. Its core is the MethodHandle class. We can such instances with for example Lookup.findSetter() (to write to fields), and we need a Lookup instance for this. If we would use MethodHandles.publicLookup(), we could access only public members. But if a caller calls MethodHandles.lookup() and passes us this instance, we can access their private members through it. So we need to extend the inject() methods with a Lookup parameter, and callers just need to copy-paste MethodHandles.lookup() into every place they call inject().