jmeter-dev mailing list archives

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

Can they be negative for StringFromFile ?

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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message