Skip to content

GROOVY-12122: Provide a Regex timeout facility#2668

Draft
paulk-asert wants to merge 5 commits into
apache:masterfrom
paulk-asert:groovy12122
Draft

GROOVY-12122: Provide a Regex timeout facility#2668
paulk-asert wants to merge 5 commits into
apache:masterfrom
paulk-asert:groovy12122

Conversation

@paulk-asert

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR (GROOVY-12122) introduces an opt-in regex timeout facility to help mitigate catastrophic backtracking (ReDoS) by adding a runtime guard and a compile-time AST transform that rewrites Groovy’s regex operators within an annotated scope.

Changes:

  • Added groovy.util.regex.RegexGuard + RegexTimeoutException to enforce evaluation deadlines via a guarded CharSequence.
  • Added @groovy.transform.SafeRegex and SafeRegexASTTransformation to rewrite ==~ / =~ usages in annotated classes/methods/constructors into RegexGuard calls.
  • Added tests covering runtime guard behavior and AST transform rewriting, including timeout and semantic-compatibility cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/groovy/util/regex/RegexGuard.java Implements deadline-guarded regex matching/matcher creation and guarded CharSequence.
src/main/java/groovy/util/regex/RegexTimeoutException.java Introduces the unchecked exception signifying a timeout during guarded evaluation.
src/main/java/groovy/transform/SafeRegex.java Adds the @SafeRegex annotation that enables guarded regex operator rewriting in scope.
src/main/java/org/codehaus/groovy/transform/SafeRegexASTTransformation.java AST transform that rewrites regex operators to RegexGuard calls using the configured timeout.
src/test/groovy/groovy/util/regex/RegexGuardTest.groovy Tests runtime guard behavior (matches, matcher, guard, validation, and timeout behavior).
src/test/groovy/org/codehaus/groovy/transform/SafeRegexTransformTest.groovy Tests AST rewrite coverage and preserves expected operator semantics within annotated scope.

Comment thread src/main/java/groovy/util/regex/RegexGuard.java
Comment thread src/main/java/groovy/util/regex/RegexGuard.java
Comment thread src/main/java/groovy/util/regex/RegexGuard.java
@codecov-commenter

codecov-commenter commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.66013% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.7199%. Comparing base (faee99b) to head (aba6141).
⚠️ Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
...s/groovy/transform/SafeRegexASTTransformation.java 78.0488% 2 Missing and 7 partials ⚠️
...ain/groovy/groovy/typecheckers/RegexChecker.groovy 60.0000% 0 Missing and 8 partials ⚠️
src/main/java/groovy/util/regex/RegexGuard.java 88.3333% 1 Missing and 6 partials ⚠️
...g/codehaus/groovy/runtime/StringGroovyMethods.java 96.1538% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2668        +/-   ##
==================================================
+ Coverage     68.5706%   68.7199%   +0.1493%     
- Complexity      33808      34177       +369     
==================================================
  Files            1524       1539        +15     
  Lines          128141     129034       +893     
  Branches        23292      23402       +110     
==================================================
+ Hits            87867      88672       +805     
- Misses          32472      32516        +44     
- Partials         7802       7846        +44     
Files with missing lines Coverage Δ
.../java/groovy/util/regex/RegexTimeoutException.java 100.0000% <100.0000%> (ø)
...a/org/codehaus/groovy/runtime/IOGroovyMethods.java 90.0000% <100.0000%> (ø)
...ava/org/codehaus/groovy/runtime/InvokerHelper.java 73.8411% <100.0000%> (ø)
...g/codehaus/groovy/runtime/StringGroovyMethods.java 82.4190% <96.1538%> (ø)
src/main/java/groovy/util/regex/RegexGuard.java 88.3333% <88.3333%> (ø)
...ain/groovy/groovy/typecheckers/RegexChecker.groovy 75.0000% <60.0000%> (+0.6410%) ⬆️
...s/groovy/transform/SafeRegexASTTransformation.java 78.0488% <78.0488%> (ø)

... and 80 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paulk-asert paulk-asert marked this pull request as draft July 8, 2026 05:42
@testlens-app

testlens-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: aba6141
▶️ Tests: 103486 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

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.

3 participants