Search code examples
jakarta-eeglassfish-4weld

Why does Weld in GlassFish 4.1 call @PreDestroy method on already destroyed ViewScoped beans after call to invalidateSession?


I noticed this morning that my JSF application running on GlassFish 4.1 was throwing the following error when my users log out of the web application:

  • WELD-000019: Error destroying an instance null of Managed Bean [...MyAuthenticator] with qualifiers [@Default @Named @Any]

MyAuthenticator is a javax.faces.view.ViewScoped CDI bean with an @PreDestroy annotated method.

As a test, I removed the @PreDestroy annotation and verified that the error disappeared.

I then added the @PreDestroy annotation back to MyAuthenticator along with many debug messages and performed the following tests:

Test 1

  1. Logged into the application.
  2. Logged out of application.

Test 2

  1. Logged into the application.
  2. Allowed session to expire.

The debug messages showed the following behaviour in both tests:

  1. MyAuthenticator is created and the login form is displayed.
  2. MyAuthenticator is destroyed immediately after the user login form is submitted and the user is logged in.
  3. When session is invalidated or expires, Weld throws the reported error.

I believe that error is the result of Weld calling the @PreDestroy method on my already destroyed MyAuthenticator.

Questions

  • Is this a bug in Weld?
  • Can I safely ignore?

Solution

  • This issue is resolved in GlassFish 4.1.2.