Skip to content

Issue #4550 XmlConfiguration argument matching#4599

Merged
gregw merged 7 commits intojetty-9.4.xfrom
jetty-9.4.x-4550-XmlConfiguration-named-args
Feb 25, 2020
Merged

Issue #4550 XmlConfiguration argument matching#4599
gregw merged 7 commits intojetty-9.4.xfrom
jetty-9.4.x-4550-XmlConfiguration-named-args

Conversation

@gregw
Copy link
Copy Markdown
Contributor

@gregw gregw commented Feb 22, 2020

Improve #4550 argument matching by:

  • rejecting obviously non matches (with allowance for unboxing)
  • sorting methods so that derived arguments are tried before more generic (eg String before Object)

Signed-off-by: Greg Wilkins gregw@webtide.com

Improve argument matching by:
 + rejecting obviously non matches (with allowance for unboxing)
 + sorting methods so that derived arguments are tried before more generic (eg String before Object)

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw gregw requested review from joakime and sbordet and removed request for sbordet February 22, 2020 09:29
@gregw
Copy link
Copy Markdown
Contributor Author

gregw commented Feb 22, 2020

This change is to address the issue noticed by @joakime that:

the was using public boolean AbstractList.add(E e); not the one in Configurations.add(String ... configClassNames)

I think this is kind of a bad class design, but now at least we will deterministically favour a String over Object over String.... Note this doesn't fix the problem @joakime found. We would have to favour String... over Object to do that. Hmmm maybe we should ?

@gregw
Copy link
Copy Markdown
Contributor Author

gregw commented Feb 22, 2020

I have the order correct as the following test:

    private static class TestOrder
    {
        public void other(Object o)
        {
            System.err.println("object");
        }

        public void other(String... s)
        {
            System.err.println("string varargs");
        }
    }

    @Test
    public void testMethodOrdering() throws Exception
    {
        TestOrder to = new TestOrder();
        to.other("foo");
    }

prints object

@gregw
Copy link
Copy Markdown
Contributor Author

gregw commented Feb 22, 2020

Dang! still breaks things... stand by...

Improve argument matching by:
 + can unbox from any Number to any Number

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Do not check the assignability of the arguments.  Instead rely on the order of the methods.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
unbox test no longer required

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw gregw requested a review from sbordet February 24, 2020 22:03
Simplified test

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Cleanup comparator

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw gregw requested a review from sbordet February 25, 2020 14:22
Copy link
Copy Markdown
Contributor

@sbordet sbordet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than a nit in the comparator, LGTM.

if (compare == 0)
{
// favour primitive type over reference
compare = Boolean.compare(t2.isPrimitive(), t1.isPrimitive());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's subtle that t1 and t2 are inverted here.
I would prefer Boolean.compare(!t1.isPrimitive(), !t2.isPrimitive()).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's how I wrote it initially.... switching....

Cleanup comparator

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw gregw merged commit 353dc9b into jetty-9.4.x Feb 25, 2020
@gregw gregw deleted the jetty-9.4.x-4550-XmlConfiguration-named-args branch February 25, 2020 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants