jetty/jetty.project

Jetty 12 - Improve method lookup in XmlConfiguration

Open

#8.917 aberto em 18 de nov. de 2022

Ver no GitHub
 (5 comments) (0 reactions) (0 assignees)Java (1.913 forks)batch import
BugHelp WantedLow Priority

Métricas do repositório

Stars
 (3.701 stars)
Métricas de merge de PR
 (Mesclagem média 6d 14h) (48 fundiu PRs em 30d)

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.

Guia do colaborador