Wicket
  1. Wicket
  2. WICKET-5215

Better exception message when Page instantiation fails in DefaultPageFactory

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 6.8.0
    • Fix Version/s: 6.9.0, 7.0.0-M1
    • Component/s: wicket
    • Labels:
      None

      Description

      If injecting dependencies to a page fails in DefaultPageFactory.newPage, the exception message is a bit misleading:

      "Can't instantiate page using constructor '...' and argument '...'. Might be it doesn't exist, may be it is not visible (public)."

      It could also mention the possibility of failing to inject the dependencies, which seems to be the case in many occasions.

      Even better, when calling the constructor fails, it could check the existence and visibility of the constructor instead of guessing what was the problem.

        Activity

        Hide
        Martin Grigorov added a comment -

        Hi,

        I've improved the exception messages for the non-visible case with: https://git-wip-us.apache.org/repos/asf/wicket/repo?p=wicket.git;a=commitdiff;h=397f89954f753dd343f48ec68bbf3f0d0e81b6d4

        What do you mean with "injecting dependencies" ?
        Please create a failing test case in org.apache.wicket.session.DefaultPageFactoryTest if the new improvement doesn't cover all requirements.

        Show
        Martin Grigorov added a comment - Hi, I've improved the exception messages for the non-visible case with: https://git-wip-us.apache.org/repos/asf/wicket/repo?p=wicket.git;a=commitdiff;h=397f89954f753dd343f48ec68bbf3f0d0e81b6d4 What do you mean with "injecting dependencies" ? Please create a failing test case in org.apache.wicket.session.DefaultPageFactoryTest if the new improvement doesn't cover all requirements.
        Hide
        Edvard Fonsell added a comment -

        By "injecting dependencies" I mean the thing that SpringComponentInjector does. But the issue is more generic, runtime exceptions thrown by any IComponentInstantiationListener trigger the same problem. I hope this failing test will clarify the requirements:

        public static class TestWebPage extends WebPage {
        public TestWebPage()

        { super(); }

        }

        @Test
        public void pageInstantiationFails() {
        tester.getApplication().getComponentInstantiationListeners().add(new IComponentInstantiationListener() {
        @Override
        public void onInstantiation(Component component)

        { throw new RuntimeException("Component instantiation failed"); }

        });
        expectedException.expect(WicketRuntimeException.class);
        expectedException.expectMessage("Can't instantiate page 'org.apache.wicket.session.DefaultPageFactoryTest$TestWebPage'. Component instantiation failed");
        pageFactory.newPage(TestWebPage.class);
        }

        Show
        Edvard Fonsell added a comment - By "injecting dependencies" I mean the thing that SpringComponentInjector does. But the issue is more generic, runtime exceptions thrown by any IComponentInstantiationListener trigger the same problem. I hope this failing test will clarify the requirements: public static class TestWebPage extends WebPage { public TestWebPage() { super(); } } @Test public void pageInstantiationFails() { tester.getApplication().getComponentInstantiationListeners().add(new IComponentInstantiationListener() { @Override public void onInstantiation(Component component) { throw new RuntimeException("Component instantiation failed"); } }); expectedException.expect(WicketRuntimeException.class); expectedException.expectMessage("Can't instantiate page 'org.apache.wicket.session.DefaultPageFactoryTest$TestWebPage'. Component instantiation failed"); pageFactory.newPage(TestWebPage.class); }
        Hide
        Martin Grigorov added a comment -

        An additional improvement has been added for this use case too.

        Show
        Martin Grigorov added a comment - An additional improvement has been added for this use case too.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Edvard Fonsell
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development