You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Christoph Läubrich (JIRA)" <ji...@apache.org> on 2014/01/08 20:26:50 UTC

[jira] [Created] (WICKET-5466) ListenerInterfaceRequestHandler#respond throws ComponentNotFoundException as a side-effect

Christoph Läubrich created WICKET-5466:
------------------------------------------

             Summary: ListenerInterfaceRequestHandler#respond throws ComponentNotFoundException as a side-effect
                 Key: WICKET-5466
                 URL: https://issues.apache.org/jira/browse/WICKET-5466
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 6.12.0
            Reporter: Christoph Läubrich


The following exception occurs instead of a generic WicketRuntimeException:

16:27:56.181 WARN  (RequestCycle.java:343) Handling the following exception [qtp9826071-207]
org.apache.wicket.core.request.handler.ComponentNotFoundException: Could not find component 'xyz' on page 'class MyPage’
       at org.apache.wicket.core.request.handler.PageAndComponentProvider.getComponent(PageAndComponentProvider.java:182) ~[org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.getComponent(ListenerInterfaceRequestHandler.java:90) ~[org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:231) ~[org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861) ~[org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) ~[org.apache.wicket.request_6.12.0.jar:6.12.0]
       at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261) [org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218) [org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289) [org.apache.wicket.core_6.12.0.jar:6.12.0]
       at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259) [org.apache.wicket.core_6.12.0.jar:6.12.0]

in fact, this is a side effect, if you look at the code:

       @Override
       public void respond(final IRequestCycle requestCycle)
       {
             final IRequestablePage page = getPage();
             final boolean freshPage = pageComponentProvider.isPageInstanceFresh();
             final boolean isAjax = ((WebRequest)requestCycle.getRequest()).isAjax();
             IRequestableComponent component = null;
             try
             {
                    component = getComponent();
             }
             catch (ComponentNotFoundException e)
             {
                    // either the page is stateless and the component we are looking for is not added in the
                    // constructor
                    // or the page is stateful+stale and a new instances was created by pageprovider
                    // we denote this by setting component to null
                    component = null;
             }
             if ((component == null && freshPage) ||

                    (component != null && getComponent().getPage() == page))

             {
             [....]
             }

             else

             {

                    throw new WicketRuntimeException("Component " + getComponent() +

                          " has been removed from page.");

             }

       }

You see that getComponent() is called twice.

1) Once guarded by a catch and once unguarded. So if the component can't be found AND freshPage is false, as a sideeffect instead of the WicketRuntimeException with the removed message a componentnotfound exception is raised as a side effect.

I see two possible solutions for this

a) either it is intentional that a ComponentNotFoundException is thrown, then it should be thrown from the catch block like

             catch (ComponentNotFoundException e)
             {
                    if (!freshPage) {
                       throw e;
                    }
             }

b) if it is unintentionall in the else case ther should be a simple check like this

 if (component == null) {
                        throw new WicketRuntimeException("Component for path " + getPath() +
                          " and page "+page.getClass().getName()+" has been removed from page.");
                    } else {
                       throw new WicketRuntimeException("Component " + component +
                          " has been removed from page.");
                    }


Beside this: it would be a good idea to mention at least the page class in either case.




--
This message was sent by Atlassian JIRA
(v6.1.5#6160)