You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Jason Pyeron <jp...@pdinc.us> on 2011/04/15 03:28:51 UTC

Fixing NPE in package org.apache.struts2.portlet.util.PortletUrlHelper need advise

Looking at: 

    public static Map ensureParamsAreStringArrays(Map<String, Object> params) {
        Map<String, String[]> result = null;
        if (params != null) {
            result = new LinkedHashMap<String, String[]>(params.size());
            Iterator<Map.Entry<String, Object>> it =
params.entrySet().iterator();
            while (it.hasNext()) {
            	Map.Entry<String, Object> entry = it.next();
            	Object val = entry.getValue();
		    if (val==null)
		    {
			// result.put(entry.getKey(),null);
			// or
			// result.put(entry.getKey(),new String[]{});
			// or
			// result.put(entry.getKey(),new String[]{""});
			// or
			// result.put(entry.getKey(),new String[]{null});
		    }
                else if (val instanceof String[]) {
                    result.put(entry.getKey(), (String[])val);
                } else {
                    result.put(entry.getKey(), new String[] { val.toString() });
                }
            }
        }
        return result;
    }


Looging at
http://portals.apache.org/pluto/portlet-2.0-apidocs/javax/portlet/BaseURL.html#s
etParameters(java.util.Map),
which is the intended consumer of the output from this method it is not clear.
But looking at
http://portals.apache.org/pluto/portlet-2.0-apidocs/javax/portlet/BaseURL.html#s
etParameter(java.lang.String,%20java.lang.String), it is looking like
result.put(entry.getKey(),null) would be valid and proper.

If we don't want the paramter to be removed then result.put(entry.getKey(),new
String[]{""}) would be the best course of action.

https://issues.apache.org/jira/browse/WW-3606

-Jason

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Principal Consultant              10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


RE: Fixing NPE in package org.apache.struts2.portlet.util.PortletUrlHelper need advise

Posted by Jason Pyeron <jp...@pdinc.us>.
> -----Original Message-----
> From: Jason Pyeron 
> Sent: Thursday, April 14, 2011 21:29
> To: 'Struts Developers List'
> Subject: Fixing NPE in package 
> org.apache.struts2.portlet.util.PortletUrlHelper need advise
> 
<snip/>
> 
> If we don't want the paramter to be removed then 
> result.put(entry.getKey(),new
> String[]{""}) would be the best course of action.
> 
> https://issues.apache.org/jira/browse/WW-3606
> 

Turns out new String[]{} is the most acceptable option after testing the others

https://issues.apache.org/jira/secure/attachment/12476411/WW-3606-null-parameter
-NPE-v2.patch

-Jason


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                      PD Inc. http://www.pdinc.us -
- Principal Consultant              10 West 24th Street #100    -
- +1 (443) 269-1555 x333            Baltimore, Maryland 21218   -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.

 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org