jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1380843 - /jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
Date Fri, 07 Sep 2012 14:06:03 GMT
On 7 September 2012 07:45, Philippe Mouawad <philippe.mouawad@gmail.com> wrote:
> I fixed it for IntSum and LongSum and added 2 tests to avoid somebody else
> doing the same mistake I did.

Thanks.

> Can they be negative for StringFromFile ?

In theory, yes, but it does not matter.
Once the parse has failed, there is no point calling isNumeric, we can
just log a message.

This should be a warning, as the parameters are supposed to be numeric
if present.

I'm not sure there is any need to use StringUtils.isNumeric within JMeter.


> Regards
> Philippe
>
> On Fri, Sep 7, 2012 at 2:28 AM, sebb <sebbaz@gmail.com> wrote:
>
>> On 6 September 2012 06:45, Philippe Mouawad <philippe.mouawad@gmail.com>
>> wrote:
>> > Well spotted, thanks for review.
>> >
>> > I will fix it as soon as possible and recheck calls.
>>
>> Thanks.
>>
>> There's another issue, which is that isNumeric does not allow for a
>> leading sign.
>> So it's not possible to validate negative numbers.
>>
>> > Regards
>> > Philippe
>> >
>> > On Thursday, September 6, 2012, sebb wrote:
>> >
>> >> On 4 September 2012 21:06,  <pmouawad@apache.org <javascript:;>>
wrote:
>> >> > Author: pmouawad
>> >> > Date: Tue Sep  4 20:06:50 2012
>> >> > New Revision: 1380843
>> >> >
>> >> > URL: http://svn.apache.org/viewvc?rev=1380843&view=rev
>> >> > Log:
>> >> > Avoid NumberFormatException by testing numericity
>> >>
>> >> -1; the two are not equivalent.
>> >>
>> >> There are some numbers which pass the isNumeric test but which still
>> >> generate NFE.
>> >> For example, numbers which are outside the permissible bounds for Long
>> >> or Integer (as the case may be)
>> >>
>> >> Also, for cases where the string is expected to be numeric, it's
>> >> cheaper to catch the occasional NFE which occurs if it is not numeric.
>> >>
>> >> It's only worth checking for numerics where the string type not
>> >> usually numeric - but one still has to catch NFE.
>> >>
>> >>
>> >> > Modified:
>> >> >
>> >>
>> jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
>> >> >
>> >> > Modified:
>> >>
>> jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
>> >> > URL:
>> >>
>> http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java?rev=1380843&r1=1380842&r2=1380843&view=diff
>> >> >
>> >>
>> ==============================================================================
>> >> > ---
>> >>
>> jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
>> >> (original)
>> >> > +++
>> >>
>> jmeter/trunk/src/functions/org/apache/jmeter/functions/StringFromFile.java
>> >> Tue Sep  4 20:06:50 2012
>> >> > @@ -26,6 +26,7 @@ import java.util.Collection;
>> >> >  import java.util.LinkedList;
>> >> >  import java.util.List;
>> >> >
>> >> > +import org.apache.commons.lang3.StringUtils;
>> >> >  import org.apache.jmeter.engine.util.CompoundVariable;
>> >> >  import org.apache.jmeter.samplers.SampleResult;
>> >> >  import org.apache.jmeter.samplers.Sampler;
>> >> > @@ -142,10 +143,10 @@ public class StringFromFile extends Abst
>> >> >          String start = "";
>> >> >          if (values.length >= PARAM_START) {
>> >> >              start = ((CompoundVariable) values[PARAM_START -
>> >> 1]).execute();
>> >> > -            try {
>> >> > -                myStart = Integer.valueOf(start).intValue();
>> >> > -            } catch (NumberFormatException e) {
>> >> > -                myStart = COUNT_UNUSED;// Don't process invalid
>> numbers
>> >> > +            if(StringUtils.isNumeric(start)) {
>> >> > +                myStart = Integer.parseInt(start);
>> >> > +            } else {
>> >> > +                myStart = COUNT_UNUSED;// Don't process invalid
>> numbers
>> >> >              }
>> >> >          }
>> >> >          // Have we used myCurrent yet?
>> >> > @@ -156,13 +157,12 @@ public class StringFromFile extends Abst
>> >> >
>> >> >          if (values.length >= PARAM_END) {
>> >> >              String tmp = ((CompoundVariable) values[PARAM_END -
>> >> 1]).execute();
>> >> > -            try {
>> >> > -                myEnd = Integer.valueOf(tmp).intValue();
>> >> > -            } catch (NumberFormatException e) {
>> >> > +            if(StringUtils.isNumeric(start)) {
>> >> > +                myEnd = Integer.parseInt(tmp);
>> >> > +            } else {
>> >> >                  myEnd = COUNT_UNUSED;// Don't process invalid numbers
>> >> > -                                        // (including "")
>> >> > +                // (including "")
>> >> >              }
>> >> > -
>> >> >          }
>> >> >
>> >> >          if (values.length >= PARAM_START) {
>> >> >
>> >> >
>> >>
>> >
>> >
>> > --
>> > Cordialement.
>> > Philippe Mouawad.
>>
>
>
>
> --
> Cordialement.
> Philippe Mouawad.

Mime
View raw message