ashrafiucse commented on code in PR #6759:
URL: https://github.com/apache/jmeter/pull/6759#discussion_r4736655595
##########
src/components/src/main/java/org/apache/jmeter/extractor/RegexExtractor.java:
##########
@@ -410,18 +394,54 @@ private static void saveGroups(JMeterVariables vars,
String basename, java.util.
* basename_gn, where n=0...# of groups<br/>
* basename_g = number of groups (apart from g0)
*/
+ /**
+ * Parses the given string as a signed decimal integer without relying on
+ * exceptions, so the hot path of failing extractions does not pay for
+ * exception creation (see issue #6240).
+ *
+ * @param s string to parse, may be null, empty or not a number
+ * @param defaultValue value to return when the string cannot be parsed
+ * @return the parsed value, or {@code defaultValue} if the string is null,
+ * empty, not a signed decimal number, or overflows an {@code int}
+ */
+ private static int parseIntOrDefault(String s, int defaultValue) {
+ if (s != null && !s.isEmpty() && isSignedDigits(s)) {
+ try {
+ return Integer.parseInt(s);
+ } catch (NumberFormatException overflow) {
+ // Digit string longer than the int range, fall through to the
default
+ }
+ }
+ if (s != null && !s.isEmpty()) {
+ log.warn("Could not parse number: '{}'", s);
Review Comment:
> A non-numeric `_g` was silently treated as 0 before, and now logs a
warning. That's fine by me, but the PR description says the behaviour is
unchanged.
Fair point — the description now states it explicitly: a non-numeric
`<refname>_g` (only possible when the variable is overwritten from outside)
logs the same "Could not parse number" warning as the other call sites instead
of failing silently, and everything else is unchanged. Fixed in 34cbbd3.
##########
xdocs/changes.xml:
##########
@@ -109,6 +109,7 @@ Summary
<ch_section>Bug fixes</ch_section>
<h3>General</h3>
<ul>
+ <li><issue>6240</issue>Regular Expression Extractor created a
<code>NumberFormatException</code> (caught and discarded) on every failed
extraction. Failed extractions no longer create exceptions when cleaning up the
group variables.</li>
Review Comment:
> Please add `<pr>6759</pr>` here.
Added. Fixed in 34cbbd3.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]