Jetty 12 - Improve method lookup in XmlConfiguration
#8917 opened on Nov 18, 2022
Description
Jetty version(s) 12+
Description Following #8915, the XML has become a little more verbose in those cases where there is need to invoke a method on a JDK private implementation class.
@joakime pointed out that if we do class hierarchy lookup and interface hierarchy lookup, and put the interface methods before the class methods in the correct order (the ones more up in the hierarchy first), then we will find the interface Method that is accessible before the private class method, so the invocation will succeed.
We exchange the cost of adding an XML attribute (as it is now) but not doing a complete class/interface lookup, with the cost of always doing a complete class/interface lookup but a a cleaner XML.
Note that we must recursively lookup also interfaces because, assuming PrivateRunnable and ConcreteRunnable are private JDK classes:
interface PrivateRunnable extends Runnable {}
class ConcreteRunnable implements PrivateRunnable {
public void run() {}
}
// Runnable *not* listed.
ConcreteRunnable.class.getInterfaces() => Class[1] { interface PrivateRunnable }
So in order to call the run() method on an object of class ConcreteRunnable, we must obtain a Method object by looking it up from Runnable.run(), since neither ConcreteRunnable.run() nor PrivateRunnable.run() would work.