This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 56273f6c7 Stabilize Strings replacement memory regression test (#1884)
56273f6c7 is described below

commit 56273f6c7347130114e9c5b269373805d7ce978c
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Nov 17 08:11:13 2026 -0500

    Stabilize Strings replacement memory regression test (#1884)
    
    Reduce the two-match workload to leave headroom for UTF-16 builder
    growth and result copying. Preserve the 64 MiB heap limit and large
    single-match workloads that detect excessive allocation.
    
    Add scenario diagnostics to help identify future probe failures.
    
    Assisted-By: OpenAI Codex
---
 .../org/apache/commons/lang3/StringsReplaceMemoryTest.java     | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/lang3/StringsReplaceMemoryTest.java 
b/src/test/java/org/apache/commons/lang3/StringsReplaceMemoryTest.java
index 822fed874..a2edbc117 100644
--- a/src/test/java/org/apache/commons/lang3/StringsReplaceMemoryTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringsReplaceMemoryTest.java
@@ -42,6 +42,7 @@ class StringsReplaceMemoryTest extends AbstractLangTest {
     public static final class MemoryProbe {
 
         private static void check(final Strings strings, final String 
replacement, final String search, final int max) {
+            System.out.println("Checking full-input replacement with " + 
replacement.length() + " replacement characters");
             final String result = strings.replace("ab", search, replacement, 
max);
             if (!result.equals(replacement)) {
                 throw new AssertionError("The full-input replacement must 
equal the replacement string");
@@ -49,6 +50,7 @@ private static void check(final Strings strings, final String 
replacement, final
         }
 
         private static void checkMultipleMatches(final Strings strings, final 
String replacement, final String search, final int max) {
+            System.out.println("Checking multiple matches with " + 
replacement.length() + " replacement characters");
             final String result = strings.replace("ab!ab", search, 
replacement, max);
             if (result.length() != 2 * replacement.length() + 1 || 
!result.startsWith(replacement) || !result.endsWith(replacement)
                     || result.charAt(replacement.length()) != '!') {
@@ -57,6 +59,7 @@ private static void checkMultipleMatches(final Strings 
strings, final String rep
         }
 
         private static void checkSparseMatch(final Strings strings, final 
String replacement, final String search, final int max) {
+            System.out.println("Checking a sparse match with " + 
replacement.length() + " replacement characters");
             // Many matches could fit by length, but only one actually occurs.
             final String suffix = StringUtils.repeat('z', 126);
             final String result = strings.replace("ab" + suffix, search, 
replacement, max);
@@ -76,12 +79,13 @@ public static void main(final String[] args) {
             final Strings strings = ignoreCase ? Strings.CI : Strings.CS;
             final String search = ignoreCase ? "AB" : "ab";
             for (final char ch : new char[] { 'x', '\u0101' }) {
-                // The former 16-match estimate needs over 64 MB even with 
compact strings; actual results fit on Java 8 as well.
-                // Leave headroom for the two-match UTF-16 result with Serial 
GC.
+                System.out.println("ignoreCase=" + ignoreCase + ", max=" + max 
+ ", character=U+" + Integer.toHexString(ch));
+                // The former 16-match estimate exceeds the 64 MiB heap even 
with compact strings.
                 final String replacement = StringUtils.repeat(ch, 4_250_000);
                 check(strings, replacement, search, max);
                 checkSparseMatch(strings, replacement, search, max);
-                checkMultipleMatches(strings, replacement, search, max);
+                // Leave room for UTF-16 builder growth and the final result 
copy when replacing two matches.
+                checkMultipleMatches(strings, StringUtils.repeat(ch, 
1_000_000), search, max);
             }
             System.out.println("Completed replacement memory checks");
         }

Reply via email to