Description
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
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 -
2) 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)
}
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.