Skip to content

Collect listener log data without running page lifecycle callbacks - #1998

Open
reiern70 wants to merge 3 commits into
masterfrom
listener-log-data-1653
Open

reiern70 wants to merge 3 commits into
masterfrom
listener-log-data-1653

Conversation

@reiern70

@reiern70 reiern70 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1653

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. 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.

What it does now

  • IPageAndComponentProvider gets an abstract 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; the component path and the page data are collected as before.
  • Resolving the component while the request is processed is unchanged: respond() still calls getComponent(), 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, 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.

The other handlers were checked: PageLogData(IPageProvider) never creates a page or runs a callback, the Ajax and WebSocket handlers log an existing page, and BookmarkableListenerRequestHandler builds no log data.

What applications see

Log entries lack 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. A class implementing IPageAndComponentProvider directly no longer compiles until it implements hasComponent(); one extending PageAndComponentProvider inherits its answer. The method has no default because no default is right: false would silently drop the component from the log data of every existing custom provider, true would promise that getComponent() has no side effects. migration-to-12.md has 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

ListenerLogDataTest now extends WicketTestCase:

  • missingComponentOfStatelessPageRunsNoLifecycleCallbacks: the issue's reproduction. No onInitialize, onConfigure or onBeforeRender during 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 after onEndRequest (the old code ran onConfigure twice more).
  • logDataNamesComponentResolvedForListener: a link added in onInitialize is clicked, and the log data still names its class and path.
  • logDataNamesBehaviorOfListener and logDataNamesSubmittingComponentOfForm: 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; neverFailsWhenComponentFails has it answer true, so the throwing getComponent() is reached.

The first three fail without the fix. mvn clean verify -Pjs-test is green.

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-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 62.99%. Comparing base (c7a21a5) to head (4ee2c93).
⚠️ Report is 1 commits behind head on master.

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:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 papegaaij left a comment

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.

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 @since to 12.0.0. The commit message needs to justify adding an abstract method to a public interface.
  • Add a section to migration-to-12.md that introduces the new method and explains how to implement it: return true only when getComponent() can return the component without creating the page or running its lifecycle callbacks.
  • In neverFails (WICKET-6908), have the anonymous provider's hasComponent() throw like its other methods. Right now it inherits false, so the throwing getComponent() is never reached, and the test no longer covers the component path.
  • Add assertions for getBehaviorClass(), getSubmittingComponentClass() and getSubmittingComponentPath(). Those are the lines ListenerLogData now 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()

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.

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.

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.

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());

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.

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.

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.

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
@reiern70

Copy link
Copy Markdown
Contributor Author

Thanks, I addressed all four points in a83421d, on top of the earlier commits:

  • hasComponent() is abstract, with @since 12.0.0, and the commit message explains why it is added to a public interface without a default.
  • migration-to-12.md has a section on hasComponent(): return true only when getComponent() can return the component without creating the page or running its lifecycle callbacks. It also describes the change in the log data.
  • In neverFails (WICKET-6908) the provider now throws from hasComponent() too. A throwing hasComponent() alone still doesn't reach getComponent(), so I added neverFailsWhenComponentFails, where hasComponent() answers true and the throwing getComponent() is called. The anonymous provider became a nested FailingProvider for that.
  • New tests assert getBehaviorClass(), getSubmittingComponentClass() and getSubmittingComponentPath() for an Ajax behavior and a form submit.

I closed #2003 and #2004 and updated the description. mvn clean verify -Pjs-test is green.

@reiern70
reiern70 requested a review from papegaaij November 24, 2026 14:51

@papegaaij papegaaij left a comment

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.

Thanks, everything from the previous review is addressed. One small thing left in the migration guide, see the inline comment.

Comment thread migration-to-12.md

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.

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.

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.

@papegaaij

Copy link
Copy Markdown
Contributor

One thing is still open from my approval, see #1998 (comment): please drop the last paragraph of the hasComponent() section in migration-to-12.md, the one starting "The log data of a listener request no longer runs the lifecycle callbacks…".

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.

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.

ListenerRequestHandler.detach() can trigger rendering callbacks after the response has been flushed

3 participants