jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

XmlConfiguration should prefer exact class match rather than interface match

Open janbartel opened this issue 1 year ago • 1 comments
trafficstars

jetty-12

When matching xml to class methods to satisfy a <Call> clause, the code currently prefers matching an argument that is an interface rather than an exact class type match. In other words, given the following java code:


    public class Example
    {
      interfact TestInterface {}
      public class TestImpl implements TestInterface {}
 
      public static void callStaticWithVarArgs(TestInterface i, String... strings)
      {
      }

      public static void callStaticWithVarArgs(TestImpl i, String... strings)
      {
      }
  }

And given the following xml:

   <Call class="Example" name="callStaticWithVarArgs">
    <Arg>
      <New class="Example$TestImpl"/>
    </Arg>
    <Arg>
      <Array type="java.lang.String">
        <Item>A</Item>
        <Item>B</Item>
        <Item>C</Item>
      </Array>
    </Arg>
  </Call>

The method callStaticWithVarArgs(TestInterface i, String... strings) is ranked higher than the alternative method - which is actually an exact match - and thus selected.

janbartel avatar Jun 10 '24 01:06 janbartel

I think this fix probably introduced the behaviour where interface args are preferenced: https://github.com/jetty/jetty.project/issues/10143

janbartel avatar Jun 10 '24 05:06 janbartel

Fixed via #11901

janbartel avatar Oct 31 '24 04:10 janbartel