[ https://issues.apache.org/struts/browse/WW-3306?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=47030#action_47030
]
Andreas Krüger commented on WW-3306:
------------------------------------
Thank you. This is already better.
But, unfortunately our real world application still wasn't happy.
To reproduce the problem the real world application exposes,
I enhanced the model class and the jsp as follows.
When this bug is solved, the enhanced JSP as below should not throw an error,
even if struts.el.throwExceptionOnFailure=true .
========================================
public class StrutsBugModel {
final private StrutsBugModel deep;
public StrutsBugModel() {
this(true);
}
private StrutsBugModel(boolean needDeep) {
if(needDeep)
deep = new StrutsBugModel(false);
else
deep = null;
}
public String getModelprop() {return null;}
public void setModelprop(String foo) {throw new UnsupportedOperationException();}
public StrutsBugModel getDeep() {return deep;}
public void setDeep(StrutsBugModel deep) {throw new UnsupportedOperationException();}
@Override
public String toString() {
if(deep == null)
return "shallow model";
else
return "deep model";
}
}
========================================
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Weird struts behaviour</title>
</head>
<body>
<h1>Weird struts behaviour</h1>
<p style="font-size:120%">See <a href="https://issues.apache.org/struts/browse/WW-3306">https://issues.apache.org/struts/browse/WW-3306</a>
.</p>
<h2>All of these work</h2>
<s:if test="modelprop == null">
<p>Property <code>modelprop</code> from the model is null, as <code><s:if></code>
is happy to tell us.</p>
</s:if>
<s:else>
<p>Property <code>modelprop</code> from the model is not null. (Well,
it is, so this text never shows.)</p>
</s:else>
<s:if test="actionprop == null">
<p>Property <code>actionprop</code> from the action is null, as <code><s:if></code>
is happy to tell us.</p>
</s:if>
<s:else>
<p>Property <code>actionprop</code> from the action is not null. (Well,
it is, so this text never shows.)</p>
</s:else>
<p>Applying a null into the text, from an action property, here it comes: “<s:property
value="actionprop" />” -
this works and causes no problems, even though we have set
<code>struts.el.throwExceptionOnFailure=true</code> in <code>struts.properties</code>
.</p>
<h2>This now works - it did not before</h2>
<p>Applying a null into the text from a model property, here it comes: “<s:property
value="modelprop" />”.</p>
<h2>This does not work: Nested property with null value</h2>
<p>Accessing a nested property (via <code>toString()</code>) isn't in itself
a problem: “<s:property value="deep.toString()" />”</p>
<s:if test="bomb">
<p>Accessing a nested null property: “<s:property value="deep.modelProp"
/>”</p>
</s:if>
<s:else>
<p><s:a ><s:param name="bomb" value="true"/>Click here</s:a> to
expose the bug.</p>
</s:else>
</body>
</html>
========================================
For the record:
We want our test environment to deviate from the production environment
as little as possible, and we will not (be allowed to) use a non-released
version in our production environment. So this is what I did for the test:
svn co -r2059 http://svn.opensymphony.com/svn/xwork/trunk xwork
svn merge -r2063:2064 http://svn.opensymphony.com/svn/xwork/trunk xwork
find xwork -name pom.xml | xargs grep -l 2.1.6 /dev/null |
xargs perl -i.oripom -wpe 's/2\.1\.6/2.1.6.1/'
cd xwork
Then, DefaultValidatorFileParserTest#testParserWithBadXML2() gave line number -1,
not the expected line number 8. I worked around this problem (without fixing).
Secondly, org.apache.maven.shared:maven-repository-builder:jar:1.0-alpha-1
could not be found. I went to xwork/assembly/pom.xml and changed the version
of maven-assembly-plugin to 2.2-beta-4 (twice).
After that,
mvn -U clean install
mvn -U source:jar
> Null value accepted from action property, but not model property when throwExceptionOnFailure=true
> --------------------------------------------------------------------------------------------------
>
> Key: WW-3306
> URL: https://issues.apache.org/struts/browse/WW-3306
> Project: Struts 2
> Issue Type: Bug
> Components: Value Stack
> Affects Versions: 2.2.0
> Reporter: Andreas Krüger
> Fix For: 2.2.0
>
>
> In this project, we experiment with setting struts.el.throwExceptionOnFailure=true to
catch errors.
> We use <s:property value="myprop" /> in our JSP.
> Occasionally, the property thus referenced is null. We want struts to insert an empty
string in that case.
> This it duely does, when either struts.el.throwExceptionOnFailure=false or when the property
is from an action object.
> However, if the property is from a model object and struts.el.throwExceptionOnFailure=true,
this bombs out.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
|