|
[
Permlink
| « Hide
]
Gunther Olesch added a comment - 01/Nov/05 06:09 AM
a patch fixing the issue.
I have digged a little deeper into the problem as it seemed to me that there should never be a return value of null in the first place. Here is what I came up with:
Here is the Exception again org.apache.turbine.services.pull.tools.TemplateLink.addPathInfo threw Exception java.lang.NullPointerException at org.apache.turbine.util.uri.TemplateURI.add(TemplateURI.java:274) So looking in TemplateURI's add Method, the first thing done is to call keySet() on the ParameterParser to retrieve all the Keys within the request. Then the Method getStrings is called for each Key within the KeySet on the ParameterParser Object. The ParameterParser is most certainly an Instance of the DefaultParameterParser which inherits from BaseValueParser. If we do now have a form submission which contains an input field of type file, we have a problem because the ParameterParser maintains two maps internally one for fileItems and one for the other parameters. But keySet returns all the Keys that are within the request by returning a CompositeSet with the keys from both maps. BUT the Method getStrings just checks the Map without the fileItems. That is why the Key is never found, and null is returned. Then I compared t2.3.2's source with t2.3.1's source and found that the Method keySet() there did not return a CompositeSet of the fileItems and the rest, but only the restKeys. I hope i could get the problem across... I added a coupld of test cases to TurbineURITest in the 2.3 branch to try and catch this problem but my tests pass.
Under what circumstances would pp.getStrings(key) return null? I have added a method to the DefaultParameterParserTest, which addresses this issues. As you can see it falis ;) and does the same as does TemplateURI in Line 273
HTH Buddy well the Problem I am adressing is the fact that the DefaultParameterParser provides the function keySet() which looks like
public Set keySet() { return new CompositeSet(new Set[] { super.keySet(), fileParameters.keySet() } ); } as you can see this returns a CompositeSet made up of 2 seperate Sets, TemplateURI makes use of this function within protected void add(int type, ParameterParser pp) { for(Iterator it = pp.keySet().iterator(); it.hasNext();) <<----- here is the call { String key = (String) it.next(); if (!key.equalsIgnoreCase(CGI_ACTION_PARAM) && !key.equalsIgnoreCase(CGI_SCREEN_PARAM) && !key.equalsIgnoreCase(CGI_TEMPLATE_PARAM)) { String[] values = pp.getStrings(key); <---- this is causing the problem though if(values != null) { for (int i = 0; i < values.length; i++) { add(type, key, values[i]); } } else { add(type, key, ""); } } } } getStrings is a Method defined in the BaseValueParser which does not know about the fileParameters Map. get Strings calls public String[] getStrings(String name) { return getParam(name); } which calls protected String [] getParam(final String name) { String key = convert(name); return (key != null) ? (String []) parameters.get(key) : null; } which does as you see not know about fileParameters Map. So in my eyes as long as DefaultParameterParser.KeySet() returns the keys of Both Maps, one would get a NPE if he is using TemplateURI.add(Integer, ParameterParser) if he has uploaded a File before. Hopefully this explanation shows the problem and why I think the problem is at least to this extend a Prolem within TemplateURI |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||