HttpSessionBindingListener valueBound and valueUnbound Methods Not Called on Jenkins Login and Logout (Working in 2.440.3 but Not in 2.479.2)

Hello Team,

I’m facing an issue with the HttpSessionBindingListener implementation in Jenkins. The valueBound() and valueUnbound() methods are not being triggered during Jenkins login and logout as expected.

Issue Details

  • Jenkins Version 2.440.3: Works as expected. Both valueBound() and valueUnbound() are called at the right moments.
  • Jenkins Version 2.479.2: The methods are not called during login and logout.

What I’m Trying to Achieve

  • valueBound() should be called when the object is added to the session.
  • valueUnbound() should be called when session.invalidate() is executed or when the object is explicitly removed via session.removeAttribute().

Questions

  1. Has there been any change in the session management logic between Jenkins 2.440.3 and 2.479.2?
  2. Does Jenkins now use a custom session management mechanism that bypasses HttpSessionBindingListener?
  3. Is there any alternative way to achieve the same behavior — to detect when an object is added or removed from the session?

Any guidance or suggestions on how to resolve this issue would be greatly appreciated.

The most obvious change is that Jenkins is now on Java EE9 which means it uses jakarta instead of javax for the servlet api.

Thank you for your prompt reply.
While using Jakarta, I encountered the following error. However, the class is available, and I have explicitly added the Jakarta servlet dependency in my pom.xml .
Error
[WARNING] Failed startup of context o.e.j.m.p.MavenWebAppContext@2b102cdf{Jenkins v2.479.2,/jenkins,file:///D:/myproject/target/jetty/webapp/,UNAVAILABLE}{C:\Users.m2\repository\org\jenkins-ci\main\jenkins-war\2.479.2\jenkins-war-2.479.2.war}
java.lang.NoClassDefFoundError: jakarta/servlet/ServletContextListener