javaee / mojarra

PLEASE NOTE: This project has moved to Eclipse Foundation and will be archived under the JavaEE GitHub Organization. After Feb. 1, 2021, the new location will be github.com/javaee/mojarra. Mojarra - Oracle's implementation of the JavaServer Faces specification
https://github.com/eclipse-ee4j/mojarra
Other
164 stars 58 forks source link

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

Open javaserverfaces opened 7 years ago

javaserverfaces commented 7 years ago

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 commented 7 years ago

Reported by fjuma

javaserverfaces commented 7 years ago

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

javaserverfaces commented 7 years ago

Issue-Links: clones JAVASERVERFACES-3378

javaserverfaces commented 7 years ago

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

edburns commented 7 years ago

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 dev@javaserverfaces.java.net mailing list.

Thanks,

Ed Burns