Skip to content

Don't create exceptions in RegexExtractor on failed extractions - #6759

Open
ashrafiucse wants to merge 1 commit into
apache:masterfrom
ashrafiucse:fix/jmeter-6240-regex-extractor-nfe
Open

Don't create exceptions in RegexExtractor on failed extractions#6759
ashrafiucse wants to merge 1 commit into
apache:masterfrom
ashrafiucse:fix/jmeter-6240-regex-extractor-nfe

Conversation

@ashrafiucse

Copy link
Copy Markdown

Description

RegexExtractor now parses its internal group-count and match-count variables (<refname>_g, <refname>_matchNr) without relying on exceptions, via a small parseIntOrDefault helper. Values that are present but not numbers still log the same warning as before; absent variables yield the previous default values, so behavior is unchanged.

Motivation and Context

Fixes #6240

Every failed extraction calls RegexExtractor#removeGroups, which parsed the (still absent) group-count variable with Integer#parseInt. Parsing null always throws a NumberFormatException, which was caught and silently discarded:

try {
    groups = Integer.parseInt(vars.get(buf.toString())); // null when no match succeeded yet
} catch (NumberFormatException e) {
    groups = 0; // silent
}

So each failing extraction paid for creating and discarding an exception. In failure-heavy test runs (which are exactly the scenario a load test exercises against a struggling system), failed extractions are the hot path.

I verified this against a locally built distribution with -Xlog:exceptions=info (which reports every thrown exception, including caught ones): a test plan with a non-matching extractor over 200 iterations produced exactly 200 NumberFormatExceptions, all in RegexExtractor.removeGroups (one per failed extraction, and nothing visible in jmeter.log). A matching-extractor control run produced zero. With this change the failing run produces zero exceptions.

For scale: the exception costs roughly 0.5 µs per failed extraction, so this is a modest but free win, and it also removes the pointless churn. The remaining parseInt call inside the helper only triggers for well-formed digit strings.

How Has This Been Tested?

  • New tests in TestRegexExtractor:
    • testNoMatchOnFreshVariablesAppliesDefault: the previously exception-throwing path (no match, no prior group variables) applies the default and leaves no group variables behind
    • testNoMatchCleansUpPreviousGroupVariables: group variables from an earlier successful extraction are cleaned up on failure
    • testNoMatchWithTamperedGroupCountVariable: a corrupted <refname>_g value is handled (warn + default) without breaking the extraction
    • testAllMatchesWithTamperedMatchNumberVariable: a corrupted <refname>_matchNr value does not break all-matches mode
  • All 29 TestRegexExtractor tests and the full :src:components:test suite (553 tests) pass
  • ./gradlew classes style passes
  • End-to-end check with a locally built distribution as described above: 200 failing iterations → 0 exceptions (previously 200), all samples successful, extracted/default values unchanged

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly. (release notes entry added to xdocs/changes.xml)

Every failed extraction called RegexExtractor#removeGroups, which parsed
the (still absent) group-count variable with Integer#parseInt. Parsing
null always throws a NumberFormatException, which was caught and silently
discarded, so each failing extraction paid for creating an exception.
In failure-heavy test runs the failed extractions are the hot path, e.g.
the reporter of the issue measured thousands of discarded exceptions per
second.

Parse the internal group-count and match-count variables without relying
on exceptions. The parsing behaves like before: absent variables yield
the previous default values, and values that are present but not numbers
still log a warning.

Closes apache#6240
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.NumberFormatException per each Jmeter's 'Regular Expression Extractor' when match not found

1 participant