You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Ken X Horn <ho...@jpmorgan.com> on 2000/07/11 20:00:41 UTC
[PATCH] NPE in tags with properties returning null
Hi,
I was getting a NullPointerException while using a SelectTag, since my method
call returned null (uninitialised bean).
The relevant code is:
SelectTag.java : 229
match = method.invoke(bean, new Object[0]).toString();
if (match == null)
match = "";
the .toString() being the offending part, the check for null is too late.
The following is more like it..
BaseFieldTag.java:146
value = method.invoke(bean, new Object[0]);
if (value == null)
value = "";
results.append(value);
A quick grep reveals similar probs elsewhere:
CheckboxTag.java:191: value = (String) method.invoke(bean, new
Object[0]).toString();
RadioTag.java:176: current = method.invoke(bean, new
Object[0]).toString();
SelectTag.java:229: match = method.invoke(bean, new
Object[0]).toString();
Cheers,
Ken.
This communication is for informational purposes only. It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan & Co. Incorporated, its
subsidiaries and affiliates.
Re: [PATCH] NPE in tags with properties returning null
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Thanks Ken. I believe that the set of changes I just checked in (which now use a
BeanUtils method to do the invoke call) have dealt with all of these cases.
Please download the new version and see if I missed anything.
Craig
Ken X Horn wrote:
> Hi,
>
> I was getting a NullPointerException while using a SelectTag, since my method
> call returned null (uninitialised bean).
> The relevant code is:
>
> SelectTag.java : 229
> match = method.invoke(bean, new Object[0]).toString();
> if (match == null)
> match = "";
>
> the .toString() being the offending part, the check for null is too late.
>
> The following is more like it..
>
> BaseFieldTag.java:146
>
> value = method.invoke(bean, new Object[0]);
> if (value == null)
> value = "";
> results.append(value);
>
> A quick grep reveals similar probs elsewhere:
>
> CheckboxTag.java:191: value = (String) method.invoke(bean, new
> Object[0]).toString();
> RadioTag.java:176: current = method.invoke(bean, new
> Object[0]).toString();
> SelectTag.java:229: match = method.invoke(bean, new
> Object[0]).toString();
>
> Cheers,
>
> Ken.
>
> This communication is for informational purposes only. It is not intended as
> an offer or solicitation for the purchase or sale of any financial instrument
> or as an official confirmation of any transaction. All market prices, data
> and other information are not warranted as to completeness or accuracy and
> are subject to change without notice. Any comments or statements made herein
> do not necessarily reflect those of J.P. Morgan & Co. Incorporated, its
> subsidiaries and affiliates.
RE: [PATCH] NPE in tags with properties returning null
Posted by Robert Edgar <ro...@hkstar.com>.
Wouldnt that only work if Object was a String, if it was an Integer or some
other type you would still need the .toString()
therefore
value = method.invoke(bean, new Object[0]);
if (value == null)
result.append("");
else
results.append(value.toString());
Rob
-----Original Message-----
From: Ken X Horn [mailto:horn_ken@jpmorgan.com]
Sent: Wednesday, July 12, 2000 2:01 AM
To: struts-dev@jakarta.apache.org
Subject: [PATCH] NPE in tags with properties returning null
Hi,
I was getting a NullPointerException while using a SelectTag, since my
method
call returned null (uninitialised bean).
The relevant code is:
SelectTag.java : 229
match = method.invoke(bean, new Object[0]).toString();
if (match == null)
match = "";
the .toString() being the offending part, the check for null is too late.
The following is more like it..
BaseFieldTag.java:146
value = method.invoke(bean, new Object[0]);
if (value == null)
value = "";
results.append(value);
A quick grep reveals similar probs elsewhere:
CheckboxTag.java:191: value = (String) method.invoke(bean, new
Object[0]).toString();
RadioTag.java:176: current = method.invoke(bean, new
Object[0]).toString();
SelectTag.java:229: match = method.invoke(bean, new
Object[0]).toString();
Cheers,
Ken.
This communication is for informational purposes only. It is not intended
as
an offer or solicitation for the purchase or sale of any financial
instrument
or as an official confirmation of any transaction. All market prices, data
and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan & Co. Incorporated, its
subsidiaries and affiliates.