Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Deploying an EAR with multiple JSF WARs can result in an ArrayIndexOutOfBoundsException #4238

Open
javaserverfaces opened this issue Mar 8, 2017 · 5 comments

Comments

@javaserverfaces
Copy link
Collaborator

When deploying an EAR that contains multiple JSF web apps to JBoss EAP 6.x, the following ArrayIndexOutOfBoundsException sometimes occurs:

15:53:37,291 SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 59) Critical error during deployment: : java.lang.ArrayIndexOutOfBoundsException: 3
       at com.sun.faces.el.DemuxCompositeELResolver._addRootELResolver(DemuxCompositeELResolver.java:114) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at com.sun.faces.el.DemuxCompositeELResolver.addRootELResolver(DemuxCompositeELResolver.java:142) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at com.sun.faces.el.ELUtils.addVariableResolvers(ELUtils.java:610) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at com.sun.faces.el.ELUtils.buildFacesResolver(ELUtils.java:242) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at com.sun.faces.application.ApplicationAssociate.initializeELResolverChains(ApplicationAssociate.java:367) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at com.sun.faces.application.ApplicationImpl.performOneTimeELInitialization(ApplicationImpl.java:1320) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at com.sun.faces.application.ApplicationImpl.getELResolver(ApplicationImpl.java:464) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]
        at org.jboss.as.weld.webtier.jsf.ForwardingApplication.getELResolver(ForwardingApplication.java:220) [jboss-as-weld-7.3.2.Final-redhat-SNAPSHOT.jar:7.3.2.Final-redhat-SNAPSHOT]
        at javax.faces.application.ApplicationWrapper.getELResolver(ApplicationWrapper.java:556) [jboss-jsf-api_2.1_spec-2.1.27.Final-redhat-1.jar:2.1.27.Final-redhat-1]
        at org.jboss.seam.faces.environment.SeamApplicationWrapper$Proxy$_$$_WeldClientProxy.getELResolver(SeamApplicationWrapper$Proxy$_$$_WeldClientProxy.java) [cim-data-converters-0.8.19-SNAPSHOT.jar:0.8.19-SNAPSHOT]
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:235) [jsf-impl-2.1.27.redhat-8.jar:2.1.27.redhat-8]

The underlying issue seems to be that when multiple JSF web apps are deployed in parallel, it's possible for two threads to execute ApplicationImpl#getELResolver() at the same time. In this case, it's possible for both threads to get past the null check in ApplicationImpl#performOneTimeELInitialization, causing this initialization to be executed twice, in parallel. This ultimately results in the ArrayIndexOutOfBoundsException shown above.

The following patch fixes this problem by placing the call to performOneTimeELInitialization in a synchronized block:

diff --git a/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java b/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java
index 4a6dde5..f7fee20 100644
--- a/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java
+++ b/jsf-ri/src/main/java/com/sun/faces/application/ApplicationImpl.java
@@ -461,7 +461,11 @@ public class ApplicationImpl extends Application {
     public ELResolver getELResolver() {

         if (compositeELResolver == null) {
-            performOneTimeELInitialization();
+            synchronized(this) {
+if (compositeELResolver == null) {
+    performOneTimeELInitialization();
+}
+            }
         }

         return compositeELResolver;

Environment

EAP 6.2.2, Mojarra 2.1.27

Affected Versions

[1.2_16]

@javaserverfaces
Copy link
Collaborator Author

Reported by fjuma

@javaserverfaces
Copy link
Collaborator Author

Issue-Links:
clones
JAVASERVERFACES-3378

@javaserverfaces
Copy link
Collaborator Author

ren.zhijun.oracle said:
Use this bug to track in the Mojarra side: Bug 25683409 - JSF 1.2.15 PATCH REQUEST

@javaserverfaces
Copy link
Collaborator Author

This issue was imported from java.net JIRA JAVASERVERFACES-4234

@edburns
Copy link
Member

edburns commented Oct 29, 2017

Please see this important message regarding community contributions to
Mojarra.

https://javaee.groups.io/g/jsf-spec/message/30

Also, please consider joining that group, as that group has taken the
place of the old [email protected] mailing list.

Thanks,

Ed Burns

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants