payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
883 stars 306 forks source link

@ViewScoped affects to another view #2506

Closed r-okui closed 6 years ago

r-okui commented 6 years ago

Description


@ViewScoped does not work properly when operating the same page in two windows. The end of the scope affects to another view.

Here is the reproduction source code. https://github.com/r-okui/view_scope

Expected Outcome

Payara 4.1.1.161 ViewScope is separated in two windows.

https://github.com/r-okui/view_scope#expected-outcome

  1. Window:A Open Page1
  2. Window:B Open Page1
  3. Window:A move to anoter page
  4. Window:B controller is alive.

Current Outcome

Payara 4.1.2.181 End of ViewScope affects another window.

https://github.com/r-okui/view_scope#current-outcome

  1. Window:A Open Page1
  2. Window:B Open Page1
  3. Window:A move to anoter page
  4. Window:B controller is lost.

Steps to reproduce

  1. Open the same page in two windows.
  2. In window A, go to another page.
  3. The controller in window B is lost.

Samples

  1. Deploy this sample => https://github.com/r-okui/view_scope

CASE 1

  1. Access to http://localhost:8080/view_scoped/index.jsf in two windows.
  2. WindowA: Press NextPage button to move to Page1
  3. WindowB: Press NextPage button to move to Page1 (Index controller called @PostCountruct)

CASE 2

  1. Access to http://localhost:8080/view_scoped/page1.jsf in two windows.
  2. WindowA: Press CountUp link 5 times and controller variable is incremented to 5.
  3. WindowB: Press CountUp link 3 times and controller variable is incremented to 3.
  4. WindowA: Press BackPage button. (and now WindowB controller is lost)
  5. WindowB: Press CountUp link, but value is 1 (controller initialized).

Environment

smillidge commented 6 years ago

Thanks for the test case we will try to reproduce the issue from your test case.

arjantijms commented 6 years ago

Thanks a lot for the very detailed report.

This is caused by an (incorrect) fix for the following issue:

This became a Mojarra issue:

The original fix in 2.3 was:

Which was backported to Mojarra 2.2.14:

And eventually landed in Payara 4.1.1.171

The issue was a mid-request navigation that replaced the view root, and therefor cleaned the view map (that contains the concrete view scoped bean instances) which causes the beans to be destroyed. This was then followed by a session.invalidate within that same request later, which again tries to destroy the view scoped beans. In the case of an @Stateful @ViewScoped bean, the EJB container is responsible for destroying the bean, and it barfs on encountering a null instance.

The issue was thought to be fixed by clearing the context map, as the destroy method checks on that first, but the context map contains meta data related to view scoped bean types and has no relation to instances.

The fix was to revert this clearing of the context map, and instead check for the actual instance being null or not.

Fix is committed here: https://github.com/payara/patched-src-mojarra/commit/6914e34cddc3437c22c4b99fb4043e25b5e4cfd3#diff-9227212e21a5831a6e82023e8d621b21R181