jetty/jetty.project

Jetty 12 - Improve method lookup in XmlConfiguration

Open

#8917 aperta il 18 nov 2022

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Java (1913 fork)batch import
BugHelp WantedLow Priority

Metriche repository

Star
 (3701 star)
Metriche merge PR
 (Merge medio 6g 14h) (48 PR mergiate in 30 g)

Descrizione

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.

Guida contributor