Repository navigation
Conversation
ListenerRequestHandler builds its ListenerLogData in detach(), after the response has been written, whether or not a request logger is enabled. ListenerLogData asked the provider for the component with getComponent(), up to three times. When a stateless page lacks the component, PageAndComponentProvider.getComponent() initializes the page and prepares it for rendering, so that a component added in a lifecycle callback can still be found; when the provider holds no page yet, for instance because the page constructor threw, it creates one. So collecting log data ran the page constructor, onInitialize(), onConfigure() and onBeforeRender() during detach, once per lookup. Whatever those callbacks touch then happens too late: in the reported application onConfigure() resolved a session scoped CDI bean, and the container created an HTTP session after the response had been committed and could not send its cookie. Log data has to describe the request, not take part in it. IPageAndComponentProvider gets a default method hasComponent(): whether getComponent() can return the component without creating the page or running its lifecycle callbacks. PageAndComponentProvider answers true when it has resolved the component already, or when the page instance it already has contains a component at the path. ListenerLogData looks the component up once, and only when the provider has it; otherwise the component class, the behavior class and the submitting component stay null, while the component path and the page data are collected as before. Building the log data only while a request logger is enabled would leave the bug in place for every application that logs requests, and getLogData() is public, so listeners may read it with the logger off. Looking the component up on the page alone, with page.get(path), would lose components the provider resolved for the listener and the request then removed from the page, such as a delete link in a repeater. Asking the provider keeps those, and every case that was cheap and safe before. Resolving the component while the request is processed is unchanged: ListenerRequestHandler.respond() still calls getComponent(), which still runs the lifecycle callbacks of a stateless page to find a component added in one of them. An application that relied on the old behaviour sees log entries without componentClass, behaviorClass and the submitting component when the listener's component was not resolved during the request, where the lookup in detach could find it by running the page's lifecycle callbacks once more; those callbacks no longer run during detach. Implementations of IPageAndComponentProvider other than PageAndComponentProvider must override hasComponent() to have their component in the log data. GitHub issue #1653
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1998 +/- ##
============================================
- Coverage 62.99% 62.99% -0.01%
- Complexity 11662 11674 +12
============================================
Files 1255 1256 +1
Lines 48864 48868 +4
Branches 6910 6911 +1
============================================
- Hits 30783 30782 -1
- Misses 15397 15405 +8
+ Partials 2684 2681 -3 🚀 New features to boost your workflow:
|
The method is backported to wicket-10.x and wicket-11.x, so 10.13.0 is the first release that carries it, not 12.0.0. GitHub issue #1653
papegaaij
left a comment
There was a problem hiding this comment.
Thanks for the thorough analysis and the tests, the fix itself looks right. I do have a problem with how hasComponent() is added to the API, and that affects the backports.
With a default implementation, every existing IPageAndComponentProvider silently starts returning false. An application with its own provider that upgrades would see its request logs stop naming the component, behavior and submitter on every request, not only in the case from #1653. The code still compiles and japicmp passes, but that is not a compatible change for a maintenance release. The method shouldn't have a default at all: no default answer is right for an implementation that doesn't know about it.
So I'd like to ask for the following:
- Make
hasComponent()abstract, without a default implementation, and change@sinceto12.0.0. The commit message needs to justify adding an abstract method to a public interface. - Add a section to
migration-to-12.mdthat introduces the new method and explains how to implement it: returntrueonly whengetComponent()can return the component without creating the page or running its lifecycle callbacks. - In
neverFails(WICKET-6908), have the anonymous provider'shasComponent()throw like its other methods. Right now it inheritsfalse, so the throwinggetComponent()is never reached, and the test no longer covers the component path. - Add assertions for
getBehaviorClass(),getSubmittingComponentClass()andgetSubmittingComponentPath(). Those are the linesListenerLogDatanow computes from the single lookup, and no test checks them.
Because this adds an abstract method to a public interface, it can't go to the maintenance lines. Please close #2003 and #2004; this is a 12.0 change only.
| * @return {@code true} if {@link #getComponent()} returns the component without side effects | ||
| * @since 10.13.0 | ||
| */ | ||
| default boolean hasComponent() |
There was a problem hiding this comment.
Please drop the default implementation, along with the "The default implementation returns false" paragraph. false silently removes the component from the log data of every existing custom provider, and true would break the contract described above. An implementor has to decide this for themselves. Please also change @since to 12.0.0.
There was a problem hiding this comment.
Done in a83421d: the default implementation and its paragraph are gone, and @since is 12.0.0. The commit message explains why the method is abstract, and migration-to-12.md has a new section on how to implement it.
| ListenerLogData logData = executedListenerHandler.getLogData(); | ||
| assertEquals(LifecyclePage.class, logData.getPageClass()); | ||
| assertEquals("link", logData.getComponentPath()); | ||
| assertEquals(ClickedLink.class, logData.getComponentClass()); |
There was a problem hiding this comment.
Could you add tests for a behavior listener and a form submit as well? They would assert getBehaviorClass(), getSubmittingComponentClass() and getSubmittingComponentPath(), which are now derived from the single lookup and aren't covered anywhere.
There was a problem hiding this comment.
Added in a83421d. logDataNamesBehaviorOfListener fires an AjaxEventBehavior and checks the component class and path, the behavior class, and that there is no submitter. logDataNamesSubmittingComponentOfForm submits a form through a button and checks the form's class and path, that there is no behavior, and the button's class and path (form:submit).
hasComponent() had a default implementation returning false. Every implementation of IPageAndComponentProvider other than Wicket's PageAndComponentProvider inherited it, so an application with a provider of its own would, on upgrading, silently lose the component, behavior and submitter from the log data of every listener request, not only of the requests from GitHub issue #1653. The code still compiled and japicmp had nothing to report, but what the application logged changed without a word. true would be no better a default: it promises that getComponent() has no side effects, which only the implementation can know. The method is now abstract. Adding an abstract method to a public interface breaks every class implementing it directly, which is why it goes into 12.0.0 only and not into the maintenance lines: an implementation has to decide what to answer, and the compiler is the one place where it is told. Classes extending PageAndComponentProvider inherit its answer and see no change. migration-to-12.md says how to implement the method. ListenerLogDataTest's WICKET-6908 provider now throws from hasComponent() as from all its methods, and a second test has it answer true, so a throwing getComponent() is reached again. New tests check the behavior class of a behavior listener and the submitting component of a form submit, which ListenerLogData now derives from its single lookup of the component. GitHub issue #1653
|
Thanks, I addressed all four points in a83421d, on top of the earlier commits:
I closed #2003 and #2004 and updated the description. |
papegaaij
left a comment
There was a problem hiding this comment.
Thanks, everything from the previous review is addressed. One small thing left in the migration guide, see the inline comment.
|
|
||
| Return `true` only when `getComponent()` can return the component without creating the page or running any of its lifecycle callbacks: because the provider has resolved the component already, or because a page instance it holds already contains it. Return `false` otherwise. Wicket asks while it collects the log data of a listener request, after the response has been written, and only calls `getComponent()` when the answer is `true`; with `false`, the log data has no component class, behavior class or submitting component. | ||
|
|
||
| The log data of a listener request no longer runs the lifecycle callbacks of a page to find its component. Before, when a stateless page lacked the listener's component, collecting the log data initialized the page and prepared it for rendering once more, during detach, and a provider without a page created one. Whatever those callbacks did happened after the response had been committed; an application that created an HTTP session there got one whose cookie never reached the browser. Log entries of such requests now have no component class, behavior class or submitting component. |
There was a problem hiding this comment.
Please drop this paragraph. It describes the bug fix, not something an upgrade has to act on, and since 30d0713 the guide leaves the consequences of a fix to the commit message, which already covers them here. The two paragraphs above are what the guide owes: the new method and how to implement it.
|
One thing is still open from my approval, see #1998 (comment): please drop the last paragraph of the The migration guide covers only what an upgrade has to act on. Here that's the new abstract method and how to implement it, which the two paragraphs above it already explain. The paragraph about the log data describes the consequence of the bug fix, and since 30d0713 that goes in the commit message, which already covers it. I'd like it removed before this is merged. |
Closes #1653
ListenerRequestHandlerbuilds itsListenerLogDataindetach(), after the response has been written, whether or not a request logger is enabled.ListenerLogDataasked the provider for the component withgetComponent(), up to three times. When a stateless page lacks the component,PageAndComponentProvider.getComponent()initializes the page and prepares it for rendering, so that a component added in a lifecycle callback can still be found; when the provider holds no page yet, for instance because the page constructor threw, it creates one. So collecting log data ran the page constructor,onInitialize(),onConfigure()andonBeforeRender()during detach, once per lookup. In the reported applicationonConfigure()resolved a session scoped CDI bean, and the container created an HTTP session after the response had been committed and could not send its cookie.What it does now
IPageAndComponentProvidergets an abstract methodhasComponent(): whethergetComponent()can return the component without creating the page or running its lifecycle callbacks.PageAndComponentProvideranswerstruewhen it has resolved the component already, or when the page instance it already has contains a component at the path.ListenerLogDatalooks the component up once, and only when the provider has it. Otherwise the component class, the behavior class and the submitting component staynull; the component path and the page data are collected as before.respond()still callsgetComponent(), which still runs the lifecycle callbacks of a stateless page to find a component added in one of them.Building the log data only while a request logger is enabled would leave the bug in place for every application that logs requests, and
getLogData()is public, so listeners may read it with the logger off. Looking the component up on the page alone, withpage.get(path), would lose components the provider resolved for the listener and the request then removed from the page, such as a delete link in a repeater.The other handlers were checked:
PageLogData(IPageProvider)never creates a page or runs a callback, the Ajax and WebSocket handlers log an existing page, andBookmarkableListenerRequestHandlerbuilds no log data.What applications see
Log entries lack
componentClass,behaviorClassand the submitting component when the listener's component was not resolved during the request, where the lookup in detach could find it by running the page's lifecycle callbacks once more; those callbacks no longer run during detach. A class implementingIPageAndComponentProviderdirectly no longer compiles until it implementshasComponent(); one extendingPageAndComponentProviderinherits its answer. The method has no default because no default is right:falsewould silently drop the component from the log data of every existing custom provider,truewould promise thatgetComponent()has no side effects.migration-to-12.mdhas a section on implementing it.Backport
None. Adding an abstract method to a public interface is a 12.0.0 change, so
hasComponent()is@since 12.0.0; the backports #2003 and #2004 are closed.Tests
ListenerLogDataTestnow extendsWicketTestCase:missingComponentOfStatelessPageRunsNoLifecycleCallbacks: the issue's reproduction. NoonInitialize,onConfigureoronBeforeRenderduring detach; the log data has the page class and the path, and no component class.pageNotCreatedYetIsNotCreatedForLogData: a provider that has not created its page does not create it during detach.missingComponentRunsNoLifecycleCallbacksAfterEndOfRequest: a full request to a listener URL of a missing component runs no callback afteronEndRequest(the old code ranonConfiguretwice more).logDataNamesComponentResolvedForListener: a link added inonInitializeis clicked, and the log data still names its class and path.logDataNamesBehaviorOfListenerandlogDataNamesSubmittingComponentOfForm: the behavior class of an Ajax event behavior, and the submitting button's class and path of a form submit, both now derived from the single lookup of the component.neverFails(WICKET-6908): the provider throws from every method,hasComponent()included;neverFailsWhenComponentFailshas it answertrue, so the throwinggetComponent()is reached.The first three fail without the fix.
mvn clean verify -Pjs-testis green.