jetty/jetty.project

Jetty 12 - Improve method lookup in XmlConfiguration

開放

#8,917 建立於 2022年11月18日

 (5 則留言) (0 個反應) (0 位負責人)Java (1,913 個分叉)batch import
BugHelp WantedLow Priority

倉庫指標

星標
 (3,701 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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.

貢獻者指南