[JAVASERVERFACES-2508] CompositeComponentAttributeELResolver$ExpressionEvalMap caches FacesContext and fails in Portlet bridge renderRequest because cached FacesContext is released Created: 07/Sep/12  Updated: 13/Sep/12  Resolved: 13/Sep/12

Status: Closed
Project: javaserverfaces
Component/s: composite components, portlet
Affects Version/s: 2.1.12, 2.2.0-m04
Fix Version/s: 2.1.14, 2.2.0-m06

Type: Bug Priority: Major
Reporter: Hanspeter Duennenberger Assignee: Manfred Riem
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Portlet 2


Attachments: Text File changebundle.txt     Text File changebundle.txt     Text File Exception in CompositeComponentAttributeELResolver in Portlet render phase.txt     Zip Archive newfiles.zip    

 Description   

With Portlet 2 bridge two distinct instances of FacesContext are used for the two Portlet phases (request processing, response rendering). Now since FacesContext is cached in CompositeComponentAttributeELResolver$ExpressionEvalMap and as it seems the ELResolver's are reused by the Portlet Bridge for the two phases, during render response an already released FacesContext instance is causing:

	java.lang.IllegalStateException
	at com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:655)
	at com.sun.faces.context.FacesContextImpl.getELContext(FacesContextImpl.java:250)
	at javax.faces.context.FacesContextWrapper.getELContext(FacesContextWrapper.java:341)
	at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.get(CompositeComponentAttributesELResolver.java:349)
	at javax.el.MapELResolver.getValue(MapELResolver.java:164)
	.... 

To make this save, the cached FacesContext should be queried for it's release state and in case it's released re-cache the current FacesContext.getCurrentInstance() to make this Portlet save.



 Comments   
Comment by Hanspeter Duennenberger [ 07/Sep/12 ]

Proposed change with re-caching FacesContext when the currently cached was released before.

Comment by Hanspeter Duennenberger [ 07/Sep/12 ]

successfully run test.with.container.refresh with this change both on trunk and 2_1X branch.

Maybe some tests with mocking the two Portlet Phase with separate FacesContext instances would be nice - are there already tests with mock-portlet setup? Manfred, any tip?

Comment by Hanspeter Duennenberger [ 12/Sep/12 ]

Tried to create a JUnit test to cover this, but failed because setting up a test to let CompositeComponentAttributeELResolver access the FacesContext instance stored in the private inner class was getting too complicated.

I made a Mojarra build containing this fix and let the project with Portal setup that discovered this problem verify the fix - theyr problem was fixed with this.

Comment by Manfred Riem [ 12/Sep/12 ]

Hanspeter, can you include the entire stacktrace? I want to investigate a bit further on this issue. Thanks!

Comment by Hanspeter Duennenberger [ 12/Sep/12 ]

Attached full stacktrace as requested by Manfred.

Comment by Hanspeter Duennenberger [ 12/Sep/12 ]

Changed the fix to not use FacesContext.getCurrentInstance() but update FacesContext in ExpressionEvalMap from the method getEvalMapFor() that is always used to deliver ExpressionEvalMap.

Comment by Manfred Riem [ 13/Sep/12 ]

Applied to 2.1 branch,

svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2508, r=rogerk, fixes CompositeComponentAttributeELResolver$ExpressionEvalMap caches FacesContext and fails in Portlet bridge renderRequest because cached FacesContext is released."
Sending jsf-ri\src\main\java\com\sun\faces\el\CompositeComponentAttributesELResolver.java
Adding test\unit\src\test\java\com\sun\faces\el
Adding test\unit\src\test\java\com\sun\faces\el\CompositeComponentAttributesELResolverTest.java
Transmitting file data ..
Committed revision 10607.

Comment by Manfred Riem [ 13/Sep/12 ]

Applied to 2.2 trunk,

svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2508, r=rogerk, fixes CompositeComponentAttributeELResolver$ExpressionEvalMap caches FacesContext and fails in Portlet bridge renderRequest because cached FacesContext is released."
Sending jsf-ri\src\main\java\com\sun\faces\el\CompositeComponentAttributesELResolver.java
Transmitting file data .
Committed revision 10608.

svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2508, r=rogerk, fixes CompositeComponentAttributeELResolver$ExpressionEvalMap caches FacesContext and fails in Portlet bridge renderRequest because cached FacesContext is released."
Adding test\unit\src\test\java\com\sun\faces\el
Adding test\unit\src\test\java\com\sun\faces\el\CompositeComponentAttributesELResolverTest.java
Transmitting file data .
Committed revision 10609.

Comment by Manfred Riem [ 13/Sep/12 ]

Hanspeter, thanks for the bugfix!

Generated at Tue Mar 28 18:35:02 UTC 2017 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.