From 62857b89ffd4e41224bd89dd7887b2c9665bed29 Mon Sep 17 00:00:00 2001 From: mriem Date: Mon, 5 Jan 2015 17:20:39 +0000 Subject: [PATCH 1/4] [JBEAP-15063] Fixes https://java.net/jira/browse/JAVASERVERFACES-3621, All Flash operations cause NPE with distributable webapp and no session git-svn-id: https://svn.java.net/svn/mojarra~svn/trunk@14165 761efcf2-d34d-6b61-9145-99dcacc3edf1 --- .../com/sun/faces/context/flash/ELFlash.java | 6 +- test/servlet30/flashNoSession/pom.xml | 62 ++++++++++++++++ .../servlet30/flashnosession/FlashBean.java | 57 +++++++++++++++ .../src/main/webapp/WEB-INF/glassfish-web.xml | 11 +++ .../src/main/webapp/WEB-INF/web.xml | 31 ++++++++ .../src/main/webapp/getvar.xhtml | 17 +++++ .../src/main/webapp/setvar.xhtml | 16 +++++ .../servlet30/flashnosession/Issue3621IT.java | 71 +++++++++++++++++++ test/servlet30/pom.xml | 1 + 9 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 test/servlet30/flashNoSession/pom.xml create mode 100644 test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java create mode 100644 test/servlet30/flashNoSession/src/main/webapp/WEB-INF/glassfish-web.xml create mode 100644 test/servlet30/flashNoSession/src/main/webapp/WEB-INF/web.xml create mode 100644 test/servlet30/flashNoSession/src/main/webapp/getvar.xhtml create mode 100644 test/servlet30/flashNoSession/src/main/webapp/setvar.xhtml create mode 100644 test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java diff --git a/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java b/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java index 5f07241a36..89967f145e 100644 --- a/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java +++ b/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java @@ -405,7 +405,7 @@ public Object get(Object key) { if (null == result) { result = getPhaseMapForReading().get(key); } - if (distributable) { + if (distributable && context.getExternalContext().getSession(false) != null) { SessionHelper sessionHelper = SessionHelper.getInstance(context.getExternalContext()); assert(null != sessionHelper); @@ -443,7 +443,7 @@ public Object put(String key, Object value) { } context.getApplication().publishEvent(context, PostPutFlashValueEvent.class, key); } - if (distributable) { + if (distributable && context.getExternalContext().getSession(false) != null) { SessionHelper sessionHelper = SessionHelper.getInstance(context.getExternalContext()); assert(null != sessionHelper); @@ -808,7 +808,7 @@ private void reapFlashes() { flashInnerMap.remove(cur); } } - if (distributable) { + if (distributable && FacesContext.getCurrentInstance().getExternalContext().getSession(false) != null) { ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext(); SessionHelper sessionHelper = SessionHelper.getInstance(extContext); if (null != sessionHelper) { diff --git a/test/servlet30/flashNoSession/pom.xml b/test/servlet30/flashNoSession/pom.xml new file mode 100644 index 0000000000..94ae3d7d12 --- /dev/null +++ b/test/servlet30/flashNoSession/pom.xml @@ -0,0 +1,62 @@ + + + + + + 4.0.0 + + com.sun.faces.test.servlet30 + pom + 2.3.0-m01-SNAPSHOT + + flashNoSession + war + Mojarra ${project.version} - Test - Servlet 3.0 - Flash and no Session + + test-servlet30-flashNoSession + + + gfv3ee6 + UTF-8 + + diff --git a/test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java b/test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java new file mode 100644 index 0000000000..146fb42ef9 --- /dev/null +++ b/test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java @@ -0,0 +1,57 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package com.sun.faces.servlet30.flashnosession; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; +import javax.faces.context.FacesContext; + +@ManagedBean(name = "flashBean") +@RequestScoped +public class FlashBean { + + public void setVariable(String val) { + FacesContext.getCurrentInstance().getExternalContext().getFlash().put("var", val); + } + + public String getVariable() { + return (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("var"); + } +} diff --git a/test/servlet30/flashNoSession/src/main/webapp/WEB-INF/glassfish-web.xml b/test/servlet30/flashNoSession/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000000..6d2832e083 --- /dev/null +++ b/test/servlet30/flashNoSession/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,11 @@ + + + + /test-servlet30-flashNoSession + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/test/servlet30/flashNoSession/src/main/webapp/WEB-INF/web.xml b/test/servlet30/flashNoSession/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..11d141bb86 --- /dev/null +++ b/test/servlet30/flashNoSession/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,31 @@ + + + + + javax.faces.PROJECT_STAGE + ${webapp.projectStage} + + + javax.faces.PARTIAL_STATE_SAVING + ${webapp.partialStateSaving} + + + javax.faces.STATE_SAVING_METHOD + ${webapp.stateSavingMethod} + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + 30 + + + faces/index.xhtml + + diff --git a/test/servlet30/flashNoSession/src/main/webapp/getvar.xhtml b/test/servlet30/flashNoSession/src/main/webapp/getvar.xhtml new file mode 100644 index 0000000000..bac587d6c1 --- /dev/null +++ b/test/servlet30/flashNoSession/src/main/webapp/getvar.xhtml @@ -0,0 +1,17 @@ + + + + + Start Page + + + + + + +

NPE Bug Reproducer

+ Session: #{facesContext.externalContext.sessionMap}
+ Flash Variable: #{flashBean.variable} + + diff --git a/test/servlet30/flashNoSession/src/main/webapp/setvar.xhtml b/test/servlet30/flashNoSession/src/main/webapp/setvar.xhtml new file mode 100644 index 0000000000..502ad9f98c --- /dev/null +++ b/test/servlet30/flashNoSession/src/main/webapp/setvar.xhtml @@ -0,0 +1,16 @@ + + + + + + + + Set Flash Variable + + + Flash Variable Set: #{flashBean.setVariable('hello')}
+
+ diff --git a/test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java b/test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java new file mode 100644 index 0000000000..6222d28c6a --- /dev/null +++ b/test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 1997-2014 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package com.sun.faces.servlet30.flashnosession; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.junit.After; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; + +public class Issue3621IT { + + private String webUrl; + private WebClient webClient; + + @Before + public void setUp() { + webUrl = System.getProperty("integration.url"); + webClient = new WebClient(); + } + + @After + public void tearDown() { + webClient.closeAllWindows(); + } + + @Test + public void testCdataEscape5() throws Exception { + HtmlPage page = webClient.getPage(webUrl + "faces/setvar.xhtml"); + page = webClient.getPage(webUrl + "faces/getvar.xhtml"); + assertTrue(page.asXml().contains("hello")); + } +} diff --git a/test/servlet30/pom.xml b/test/servlet30/pom.xml index 45eec9db1d..3424385517 100644 --- a/test/servlet30/pom.xml +++ b/test/servlet30/pom.xml @@ -73,6 +73,7 @@ jarWithExactlyTwoContracts mapping multi-tenant + flashNoSession navigation resourceExposure systest From 1ab872044defe9b9e303de228665b1c9ee6c590a Mon Sep 17 00:00:00 2001 From: mriem Date: Mon, 5 Jan 2015 19:47:11 +0000 Subject: [PATCH 2/4] [JBEAP-15063] Fixes https://java.net/jira/browse/JAVASERVERFACES-3621, All Flash operations cause NPE with distributable webapp and no session git-svn-id: https://svn.java.net/svn/mojarra~svn/trunk@14167 761efcf2-d34d-6b61-9145-99dcacc3edf1 --- .../faces/{ => test}/servlet30/flashnosession/FlashBean.java | 2 +- .../faces/{ => test}/servlet30/flashnosession/Issue3621IT.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename test/servlet30/flashNoSession/src/main/java/com/sun/faces/{ => test}/servlet30/flashnosession/FlashBean.java (97%) rename test/servlet30/flashNoSession/src/test/java/com/sun/faces/{ => test}/servlet30/flashnosession/Issue3621IT.java (98%) diff --git a/test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java b/test/servlet30/flashNoSession/src/main/java/com/sun/faces/test/servlet30/flashnosession/FlashBean.java similarity index 97% rename from test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java rename to test/servlet30/flashNoSession/src/main/java/com/sun/faces/test/servlet30/flashnosession/FlashBean.java index 146fb42ef9..75915a9935 100644 --- a/test/servlet30/flashNoSession/src/main/java/com/sun/faces/servlet30/flashnosession/FlashBean.java +++ b/test/servlet30/flashNoSession/src/main/java/com/sun/faces/test/servlet30/flashnosession/FlashBean.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package com.sun.faces.servlet30.flashnosession; +package com.sun.faces.test.servlet30.flashnosession; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; diff --git a/test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java b/test/servlet30/flashNoSession/src/test/java/com/sun/faces/test/servlet30/flashnosession/Issue3621IT.java similarity index 98% rename from test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java rename to test/servlet30/flashNoSession/src/test/java/com/sun/faces/test/servlet30/flashnosession/Issue3621IT.java index 6222d28c6a..c9490c19bc 100644 --- a/test/servlet30/flashNoSession/src/test/java/com/sun/faces/servlet30/flashnosession/Issue3621IT.java +++ b/test/servlet30/flashNoSession/src/test/java/com/sun/faces/test/servlet30/flashnosession/Issue3621IT.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package com.sun.faces.servlet30.flashnosession; +package com.sun.faces.test.servlet30.flashnosession; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; From 1eca229d8fa0e4b3d16555ab962e205368549ed9 Mon Sep 17 00:00:00 2001 From: mriem Date: Fri, 20 Feb 2015 23:32:12 +0000 Subject: [PATCH 3/4] Fixes https://java.net/jira/browse/JAVASERVERFACES-3780, NPE in ELFlash.put() during ViewExpiredException processing git-svn-id: https://svn.java.net/svn/mojarra~svn/trunk@14427 761efcf2-d34d-6b61-9145-99dcacc3edf1 --- .../src/main/java/com/sun/faces/context/flash/ELFlash.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java b/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java index 89967f145e..8127235e6c 100644 --- a/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java +++ b/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java @@ -446,8 +446,9 @@ public Object put(String key, Object value) { if (distributable && context.getExternalContext().getSession(false) != null) { SessionHelper sessionHelper = SessionHelper.getInstance(context.getExternalContext()); - assert(null != sessionHelper); - sessionHelper.update(context.getExternalContext(), this); + if (sessionHelper != null) { + sessionHelper.update(context.getExternalContext(), this); + } } return result; From fd325ef9e87f9512fa93b52dd5037f3453f5f8d3 Mon Sep 17 00:00:00 2001 From: Bartosz Spyrko-Smietanko Date: Thu, 26 Jul 2018 11:20:28 +0100 Subject: [PATCH 4/4] [JBEAB-15063] NPE in ELFlash.get() on first request --- .../src/main/java/com/sun/faces/context/flash/ELFlash.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java b/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java index 8127235e6c..fc11a9ac59 100644 --- a/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java +++ b/jsf-ri/src/main/java/com/sun/faces/context/flash/ELFlash.java @@ -408,8 +408,9 @@ public Object get(Object key) { if (distributable && context.getExternalContext().getSession(false) != null) { SessionHelper sessionHelper = SessionHelper.getInstance(context.getExternalContext()); - assert(null != sessionHelper); - sessionHelper.update(context.getExternalContext(), this); + if (sessionHelper != null) { + sessionHelper.update(context.getExternalContext(), this); + } } if (LOGGER.isLoggable(Level.FINEST)) {