Skip to content

Commit

Permalink
Issue #4509 Removed faulty context map clear and replaced with check
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatej committed Aug 14, 2019
1 parent 89e82dd commit 2133903
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions impl/src/main/java/com/sun/faces/cdi/ViewScopeContextManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]

package com.sun.faces.cdi;

Expand Down Expand Up @@ -152,7 +153,18 @@ private void destroyBeans(
CreationalContext creationalContext = beanManager.createCreationalContext(contextual);
// We can no longer get this from the contextObject. Instead we must call
// beanManager.createCreationalContext(contextual)
contextual.destroy(viewMap.get(contextObject.getName()), creationalContext);
Object contextualInstance = viewMap.get(contextObject.getName());

// Contextual instance may be null if already removed from view map (and thus already destroyed).
// This can happen when a mid-request navigation happens and a new view root is being set, and then
// in the same request a session.invalidate is called.
// See https://github.com/javaserverfaces/mojarra/issues/3454
// Also see https://github.com/payara/Payara/issues/2506 for why we can't just clean the contextMap
// (it contains abstract descriptors for all instances, not just the one we want to destroy here).
if (contextualInstance != null) {
contextual.destroy(contextualInstance, creationalContext);
}

removalNameList.add(contextObject.getName());
}

Expand All @@ -161,8 +173,7 @@ private void destroyBeans(
String name = removalNames.next();
viewMap.remove(name);
}

contextMap.clear();

}
}

Expand Down

0 comments on commit 2133903

Please sign in to comment.