You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mk...@apache.org on 2011/11/28 23:28:02 UTC
svn commit: r1207660 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/renderkit/
test/java/org/apache/myfaces/renderkit/
Author: mkienenb
Date: Mon Nov 28 22:28:01 2011
New Revision: 1207660
URL: http://svn.apache.org/viewvc?rev=1207660&view=rev
Log:
MYFACES-3413: Default MyFaces Error handling throws NullPointerException during component tree when javax.el.Expression.getExpressionString() is null
Added:
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/ErrorPageWriterTest.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/NullReturningGetExpressionStringValueExpression.java
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java?rev=1207660&r1=1207659&r2=1207660&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java Mon Nov 28 22:28:01 2011
@@ -1259,7 +1259,12 @@ public final class ErrorPageWriter
valueExpression = c.getValueExpression(pd[i].getName());
if (valueExpressionValues && valueExpression != null)
{
- _writeAttribute(writer, pd[i].getName(), valueExpression.getExpressionString());
+ String expressionString = valueExpression.getExpressionString();
+ if (null == expressionString)
+ {
+ expressionString = "";
+ }
+ _writeAttribute(writer, pd[i].getName(), expressionString);
}
else
{
Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/ErrorPageWriterTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/ErrorPageWriterTest.java?rev=1207660&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/ErrorPageWriterTest.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/ErrorPageWriterTest.java Mon Nov 28 22:28:01 2011
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.renderkit;
+
+import java.io.StringWriter;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlOutputText;
+import javax.validation.constraints.AssertTrue;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
+import org.apache.myfaces.shared.util.StateUtils;
+import org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory;
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+import org.apache.myfaces.test.mock.MockRenderKitFactory;
+import org.apache.myfaces.test.mock.MockResponseWriter;
+
+/**
+ * @author Bruno Aranda (latest modification by $Author: struberg $)
+ * @version $Revision: 1188235 $ $Date: 2011-10-24 13:09:33 -0400 (Mon, 24 Oct 2011) $
+ */
+public class ErrorPageWriterTest extends AbstractJsfTestCase
+{
+ public static Test suite()
+ {
+ return new TestSuite(ErrorPageWriterTest.class); // needed in maven
+ }
+
+ private MockResponseWriter writer ;
+ private HtmlOutputText outputText;
+
+ public ErrorPageWriterTest(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ outputText = new HtmlOutputText();
+
+ writer = new MockResponseWriter(new StringWriter(), null, null);
+ facesContext.setResponseWriter(writer);
+ // TODO remove these two lines once myfaces-test goes alpha, see MYFACES-1155
+ facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
+ facesContext.getRenderKit().addRenderer(
+ outputText.getFamily(),
+ outputText.getRendererType(),
+ new HtmlTextRenderer());
+ servletContext.setAttribute(StateUtils.SERIAL_FACTORY, new DefaultSerialFactory());
+
+ facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", Boolean.TRUE);
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ outputText = null;
+ writer = null;
+ }
+
+ public void testValueExpressionGetExpressionStringReturnsNull()
+ {
+ //See MYFACES-3413 for details
+ UIViewRoot root = facesContext.getViewRoot();
+// UIForm form = new UIForm();
+// form.setId("formId");
+//
+// form.getChildren().add(inputText);
+ root.getChildren().add(outputText);
+
+ ValueExpression ve = new NullReturningGetExpressionStringValueExpression();
+
+ outputText.setValueExpression("rendered", ve);
+ String id = "testValueExpressionGetExpressionStringReturnsNullOutputComponent";
+ outputText.setId(id);
+ try
+ {
+ StringWriter w = new StringWriter();
+ Throwable t = new Throwable("Placeholder throwable");
+ ErrorPageWriter.debugHtml(w, facesContext, t);
+ String output = w.toString();
+ int indexOfOutputComponentId = output.indexOf(id);
+ String surroundingText = "output component not found.";
+ if (-1 != indexOfOutputComponentId) {
+ surroundingText = output.substring(Math.max(0, indexOfOutputComponentId - 20), Math.min(output.length(), indexOfOutputComponentId + 280));
+ }
+ int indexOfHasRenderedAttribute = output.indexOf("rendered=\"\"");
+ boolean hasRenderedAttribute = (-1 != indexOfHasRenderedAttribute);
+ assertTrue("rendered attribute wasn't written correctly: " + surroundingText, hasRenderedAttribute);
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+
+}
Added: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/NullReturningGetExpressionStringValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/NullReturningGetExpressionStringValueExpression.java?rev=1207660&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/NullReturningGetExpressionStringValueExpression.java (added)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/renderkit/NullReturningGetExpressionStringValueExpression.java Mon Nov 28 22:28:01 2011
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.renderkit;
+import java.io.Serializable;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.PropertyNotFoundException;
+import javax.el.PropertyNotWritableException;
+import javax.el.ValueExpression;
+
+public class NullReturningGetExpressionStringValueExpression extends ValueExpression implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getExpressionString() {
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext arg0) {
+ return true;
+ }
+
+ @Override
+ public Class<?> getExpectedType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext arg0)
+ throws NullPointerException, PropertyNotFoundException,
+ ELException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getValue(ELContext arg0) throws NullPointerException,
+ PropertyNotFoundException, ELException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setValue(ELContext arg0, Object arg1)
+ throws NullPointerException, PropertyNotFoundException,
+ PropertyNotWritableException, ELException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean equals(Object arg0) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean isLiteralText() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+ }
+