On 6 September 2012 06:45, Philippe Mouawad <[email protected]> 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, <[email protected] <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.
