This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_5_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_5_0_X by this push:
new e4123d96d7 GROOVY-7785: StackoverflowException when using too many
chained method calls
e4123d96d7 is described below
commit e4123d96d7e9a3a87b25f3e8e9ed9a884ad1f73f
Author: Daniel Sun <[email protected]>
AuthorDate: Sun Feb 8 04:28:55 2026 +0900
GROOVY-7785: StackoverflowException when using too many chained method calls
(cherry picked from commit f1d6e5f025a3bc8e90c09f2a217bb47e214cb89d)
---
.../classgen/asm/indy/InvokeDynamicWriter.java | 91 +++++-
src/test/groovy/bugs/Groovy7785.groovy | 308 ++++++++++++++++++++-
2 files changed, 391 insertions(+), 8 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
index 0e8245ac5c..e87b02245f 100644
---
a/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
+++
b/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
@@ -25,6 +25,7 @@ import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
import org.codehaus.groovy.ast.expr.EmptyExpression;
import org.codehaus.groovy.ast.expr.Expression;
+import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.ast.expr.PropertyExpression;
import org.codehaus.groovy.ast.tools.WideningCategories;
import org.codehaus.groovy.classgen.AsmClassGenerator;
@@ -42,8 +43,11 @@ import org.objectweb.asm.Opcodes;
import java.lang.invoke.CallSite;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.List;
+import static org.apache.groovy.ast.tools.ExpressionUtils.isSuperExpression;
import static org.apache.groovy.ast.tools.ExpressionUtils.isThisExpression;
import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.boolean_TYPE;
@@ -54,16 +58,16 @@ import static
org.codehaus.groovy.ast.ClassHelper.isWrapperBoolean;
import static org.codehaus.groovy.ast.tools.GeneralUtils.bytecodeX;
import static org.codehaus.groovy.classgen.asm.BytecodeHelper.doCast;
import static
org.codehaus.groovy.classgen.asm.BytecodeHelper.getTypeDescription;
-import static org.codehaus.groovy.vmplugin.v8.IndyInterface.GROOVY_OBJECT;
-import static org.codehaus.groovy.vmplugin.v8.IndyInterface.IMPLICIT_THIS;
-import static org.codehaus.groovy.vmplugin.v8.IndyInterface.SAFE_NAVIGATION;
-import static org.codehaus.groovy.vmplugin.v8.IndyInterface.SPREAD_CALL;
-import static org.codehaus.groovy.vmplugin.v8.IndyInterface.THIS_CALL;
import static org.codehaus.groovy.vmplugin.v8.IndyInterface.CallType.CAST;
import static org.codehaus.groovy.vmplugin.v8.IndyInterface.CallType.GET;
import static org.codehaus.groovy.vmplugin.v8.IndyInterface.CallType.INIT;
import static org.codehaus.groovy.vmplugin.v8.IndyInterface.CallType.INTERFACE;
import static org.codehaus.groovy.vmplugin.v8.IndyInterface.CallType.METHOD;
+import static org.codehaus.groovy.vmplugin.v8.IndyInterface.GROOVY_OBJECT;
+import static org.codehaus.groovy.vmplugin.v8.IndyInterface.IMPLICIT_THIS;
+import static org.codehaus.groovy.vmplugin.v8.IndyInterface.SAFE_NAVIGATION;
+import static org.codehaus.groovy.vmplugin.v8.IndyInterface.SPREAD_CALL;
+import static org.codehaus.groovy.vmplugin.v8.IndyInterface.THIS_CALL;
import static org.objectweb.asm.Opcodes.H_INVOKESTATIC;
import static org.objectweb.asm.Opcodes.IFNULL;
@@ -113,12 +117,87 @@ public class InvokeDynamicWriter extends InvocationWriter
{
// load normal receiver as first argument
compileStack.pushImplicitThis(implicitThis);
- receiver.visit(controller.getAcg());
+ // GROOVY-7785: use iterative approach to avoid stack overflow for
chained method calls
+ visitReceiverOfMethodCall(receiver);
compileStack.popImplicitThis();
return "(" + getTypeDescription(operandStack.getTopOperand());
}
+ /**
+ * Visits receiver expression, using iterative approach for method call
chains.
+ * GROOVY-7785: Flattens deep recursive AST structures to avoid stack
overflow.
+ */
+ private void visitReceiverOfMethodCall(final Expression receiver) {
+ // Collect chain of simple method calls that can use indy optimization
+ Deque<MethodCallExpression> chain = new ArrayDeque<>();
+ Expression current = receiver;
+ while (current instanceof MethodCallExpression) {
+ MethodCallExpression mce = (MethodCallExpression) current;
+ if (mce.isSpreadSafe() || mce.isImplicitThis() ||
isSuperExpression(mce.getObjectExpression()) ||
isThisExpression(mce.getObjectExpression())) {
+ break;
+ }
+ String name = getMethodName(mce.getMethod());
+ if (name == null || "call".equals(name)) break; // dynamic name or
functional interface call
+ chain.push(mce);
+ current = mce.getObjectExpression();
+ }
+
+ AsmClassGenerator acg = controller.getAcg();
+ current.visit(acg);
+
+ while (!chain.isEmpty()) {
+ MethodCallExpression call = chain.pop();
+ acg.onLineNumber(call, "visitMethodCallExpression: \"" +
call.getMethod() + "\":");
+ finishIndyCallForChain(call);
+ controller.getAssertionWriter().record(call.getMethod());
+ }
+ }
+
+ /**
+ * Completes an indy call for a chained method with receiver already on
stack.
+ */
+ private void finishIndyCallForChain(final MethodCallExpression call) {
+ OperandStack operandStack = controller.getOperandStack();
+ AsmClassGenerator acg = controller.getAcg();
+ Expression arguments = call.getArguments();
+ boolean safe = call.isSafe();
+
+ StringBuilder sig = new
StringBuilder("(").append(getTypeDescription(operandStack.getTopOperand()));
+ Label end = null;
+ if (safe && !isPrimitiveType(operandStack.getTopOperand())) {
+ operandStack.dup();
+ end = operandStack.jump(IFNULL);
+ }
+
+ int nArgs = 1;
+ List<Expression> args = makeArgumentList(arguments).getExpressions();
+ boolean spread = AsmClassGenerator.containsSpreadExpression(arguments);
+ if (spread) {
+ acg.despreadList(args, true);
+ sig.append(getTypeDescription(Object[].class));
+ } else {
+ for (Expression arg : args) {
+ arg.visit(acg);
+ if (arg instanceof CastExpression) {
+ operandStack.box();
+ acg.loadWrapper(arg);
+ sig.append(getTypeDescription(Wrapper.class));
+ } else {
+
sig.append(getTypeDescription(operandStack.getTopOperand()));
+ }
+ nArgs++;
+ }
+ }
+ sig.append(")Ljava/lang/Object;");
+
+ int flags = safe ? SAFE_NAVIGATION : 0;
+ if (spread) flags |= SPREAD_CALL;
+
controller.getMethodVisitor().visitInvokeDynamicInsn(METHOD.getCallSiteName(),
sig.toString(), BSM, getMethodName(call.getMethod()), flags);
+ operandStack.replace(OBJECT_TYPE, nArgs);
+ if (end != null) controller.getMethodVisitor().visitLabel(end);
+ }
+
private void finishIndyCall(final Handle bsmHandle, final String
methodName, final String sig, final int numberOfArguments, final Object...
bsmArgs) {
CompileStack compileStack = controller.getCompileStack();
OperandStack operandStack = controller.getOperandStack();
diff --git a/src/test/groovy/bugs/Groovy7785.groovy
b/src/test/groovy/bugs/Groovy7785.groovy
index 1f98995820..d3ff54b60d 100644
--- a/src/test/groovy/bugs/Groovy7785.groovy
+++ b/src/test/groovy/bugs/Groovy7785.groovy
@@ -18,13 +18,317 @@
*/
package bugs
+import org.junit.jupiter.api.Disabled
+import org.junit.jupiter.api.Test
+
import static groovy.test.GroovyAssert.assertScript
+/**
+ * Tests for GROOVY-7785: StackOverflowError with deeply nested chained method
calls.
+ * Each test uses chained method calls to verify the fix handles deep chains.
+ */
final class Groovy7785 {
+
+ @Test
void testManyChainedMethodCalls() {
+ // 1000 chained append calls on StringBuilder
+ assertScript '''
+ def r = new
StringBuilder().append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("
[...]
+ assert r.toString() == 'a' * 1000
+ '''
+ }
+
+ @Test
+ void testChainedCaseConversions() {
+ // 1000 chained toUpperCase/toLowerCase calls
+ assertScript '''
+ def result =
"hello".toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase().toLowerCase().toUpperCase
[...]
+ assert result == "hello" // 1000 is even, ends with toLowerCase
+ '''
+ }
+
+ @Test
+ void testChainedReplaceOperations() {
+ // 1000 chained replace calls (none match, string unchanged)
+ assertScript '''
+ def result = "test string".replace("NOTFOUND0",
"X").replace("NOTFOUND1", "X").replace("NOTFOUND2", "X").replace("NOTFOUND3",
"X").replace("NOTFOUND4", "X").replace("NOTFOUND5", "X").replace("NOTFOUND6",
"X").replace("NOTFOUND7", "X").replace("NOTFOUND8", "X").replace("NOTFOUND9",
"X").replace("NOTFOUND10", "X").replace("NOTFOUND11",
"X").replace("NOTFOUND12", "X").replace("NOTFOUND13",
"X").replace("NOTFOUND14", "X").replace("NOTFOUND15",
"X").replace("NOTFOUND16", "X").repl [...]
+ assert result == "test string"
+ '''
+ }
+
+ @Test
+ void testChainedTrimOperations() {
+ // 1000 chained trim calls (idempotent operation)
+ assertScript '''
+ def result = " hello world
".trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().t
[...]
+ assert result == "hello world"
+ '''
+ }
+
+ @Test
+ void testChainedCollectionOperations() {
+ // 1000 chained collect calls on a list
+ assertScript '''
+ def result = [1, 2, 3].collect { it }.collect { it }.collect { it
}.collect { it }.collect { it }.collect { it }.collect { it }.collect { it
}.collect { it }.collect { it }.collect { it }.collect { it }.collect { it
}.collect { it }.collect { it }.collect { it }.collect { it }.collect { it
}.collect { it }.collect { it }.collect { it }.collect { it }.collect { it
}.collect { it }.collect { it }.collect { it }.collect { it }.collect { it
}.collect { it }.collect { it }.collect [...]
+ assert result == [1, 2, 3]
+ '''
+ }
+
+ @Test
+ void testChainedBuilderPattern() {
+ // 1000 chained builder set calls
+ assertScript '''
+ class Builder {
+ private map = [:]
+ Builder set(String key, value) {
+ map[key] = value
+ return this
+ }
+ Map build() { map }
+ }
+
+ def result = new Builder().set("k0", 0).set("k1", 1).set("k2",
2).set("k3", 3).set("k4", 4).set("k5", 5).set("k6", 6).set("k7", 7).set("k8",
8).set("k9", 9).set("k10", 10).set("k11", 11).set("k12", 12).set("k13",
13).set("k14", 14).set("k15", 15).set("k16", 16).set("k17", 17).set("k18",
18).set("k19", 19).set("k20", 20).set("k21", 21).set("k22", 22).set("k23",
23).set("k24", 24).set("k25", 25).set("k26", 26).set("k27", 27).set("k28",
28).set("k29", 29).set("k30", 30).set("k31 [...]
+ assert result.size() == 1000
+ assert result.k0 == 0
+ assert result.k999 == 999
+ '''
+ }
+
+ @Test
+ void testChainedAppendWithDifferentTypes() {
+ // 1000 chained appends with mixed content (400x + 400y + 200z)
+ assertScript '''
+ def sb = new
StringBuilder().append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append("x").append(
[...]
+ assert sb.length() == 1000
+ assert sb.toString().startsWith("x" * 400)
+ assert sb.toString().endsWith("z" * 200)
+ '''
+ }
+
+ @Test
+ void testChainedNavigationDeep() {
+ // 1000 chained getNext() calls
+ assertScript '''
+ class Node {
+ Node next
+ String value = "v"
+ Node getNext() { next }
+ }
+
+ // Build a chain of 1001 nodes
+ def root = new Node()
+ def current = root
+ 1000.times {
+ current.next = new Node()
+ current = current.next
+ }
+
+ // Navigate through 1000 nodes
+ def nav =
root.getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNe
[...]
+ assert nav.value == "v"
+ assert nav.next == null
+ '''
+ }
+
+ @Test
+ void testChainedStreamOperations() {
+ // 1000 chained stream map operations
+ assertScript '''
+ import java.util.stream.Collectors
+
+ def result = [1, 2, 3].stream().map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it [...]
+ assert result == [1, 2, 3]
+ '''
+ }
+
+ @Test
+ void testChainedOptionalOperations() {
+ // 1000 chained Optional map operations
+ assertScript '''
+ def result = Optional.of(42).map { it }.map { it }.map { it }.map
{ it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map {
it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }.map { it }.map { it }.map { it }.map { it }.map { it
}.map { it }.map { it }. [...]
+ assert result == 42
+ '''
+ }
+
+ @Test
+ void testChainedFindAllOperations() {
+ // 1000 chained findAll with always-true predicate
+ assertScript '''
+ def list = [1, 2, 3, 4, 5].findAll { true }.findAll { true
}.findAll { true }.findAll { true }.findAll { true }.findAll { true }.findAll {
true }.findAll { true }.findAll { true }.findAll { true }.findAll { true
}.findAll { true }.findAll { true }.findAll { true }.findAll { true }.findAll {
true }.findAll { true }.findAll { true }.findAll { true }.findAll { true
}.findAll { true }.findAll { true }.findAll { true }.findAll { true }.findAll {
true }.findAll { true }.findAll { t [...]
+ assert list == [1, 2, 3, 4, 5]
+ '''
+ }
+
+ @Test
+ void testMixedChainedOperations() {
+ // 1000 mixed string operations (trim/toString/replace/intern)
+ assertScript '''
+ def result = "HELLO".trim().toString().replace("NOTFOUND2",
"X").intern().trim().toString().replace("NOTFOUND6",
"X").intern().trim().toString().replace("NOTFOUND10",
"X").intern().trim().toString().replace("NOTFOUND14",
"X").intern().trim().toString().replace("NOTFOUND18",
"X").intern().trim().toString().replace("NOTFOUND22",
"X").intern().trim().toString().replace("NOTFOUND26",
"X").intern().trim().toString().replace("NOTFOUND30",
"X").intern().trim().toString().replace("NO [...]
+ assert result.toLowerCase() == "hello"
+ '''
+ }
+
+ @Test
+ void testChainedWithClosureReturningThis() {
+ // 1000 chained increment operations
+ assertScript '''
+ class Counter {
+ int count = 0
+ Counter increment() { count++; this }
+ }
+
+ def c = new
Counter().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().increment().in
[...]
+ assert c.count == 1000
+ '''
+ }
+
+
+ @Test
+ void testChainedCallOperations() {
+ assertScript '''
+ def str = " hello world "
+ def result =
str.trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().t
[...]
+ assert result == "hello world"
+ '''
+ }
+
+ @Test
+ void testChainedCallOperationsInClass() {
+ assertScript '''
+ class X {
+ static void test() {
+ def str = " hello world "
+ def result =
str.trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().
[...]
+ assert result == "hello world"
+ }
+ }
+ X.test()
+ '''
+ }
+
+ @Test
+ void testChainedCallOperationsInClass_2() {
+ assertScript '''
+ class X {
+ static void test() {
+ X x = new X()
+ x.doProcess()
+ }
+ void doProcess() {
+ def str = " hello world "
+ def result = process(str)
+ assert result == "hello world"
+ }
+ def process(str) {
+ def result =
str.trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().
[...]
+ return result
+ }
+ }
+ X.test()
+ '''
+ }
+
+ /**
+ * It takes too long to compile, disable it for now.
+ */
+ @Disabled
+ @Test
+ void testChainedCallOperationsInClass_2_CS() {
+ assertScript '''
+ @groovy.transform.CompileStatic
+ class X {
+ static void test() {
+ X x = new X()
+ x.doProcess()
+ }
+ void doProcess() {
+ def str = " hello world "
+ def result = process(str)
+ assert result == "hello world"
+ }
+ def process(str) {
+ def result =
str.trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().trim().
[...]
+ return result
+ }
+ }
+ X.test()
+ '''
+ }
+
+
+ @Test
+ void testChainedSafeCallOperations() {
+ // 1000 chained safe navigation calls (?.)
+ assertScript '''
+ def str = " hello world "
+ def result =
str?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()
[...]
+ assert result == "hello world"
+ '''
+ }
+
+ @Test
+ void testChainedSafeCallOperationsInClass() {
+ // 1000 chained safe navigation calls (?.)
+ assertScript '''
+ class X {
+ static void test() {
+ def str = " hello world "
+ def result =
str?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()
[...]
+ assert result == "hello world"
+ }
+ }
+ X.test()
+ '''
+ }
+
+ @Test
+ void testChainedSafeCallOperationsInClass_2() {
+ // 1000 chained safe navigation calls (?.)
+ assertScript '''
+ class X {
+ static void test() {
+ X x = new X()
+ x.doProcess()
+ }
+ void doProcess() {
+ def str = " hello world "
+ def result = process(str)
+ assert result == "hello world"
+ }
+ def process(str) {
+ def result =
str?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()
[...]
+ return result
+ }
+ }
+ X.test()
+ '''
+ }
+
+ /**
+ * It takes too long to compile, disable it for now.
+ */
+ @Disabled
+ @Test
+ void testChainedSafeCallOperationsInClass_2_CS() {
+ // 1000 chained safe navigation calls (?.)
assertScript '''
- def r = new
StringBuilder().append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("a").append("
[...]
- assert r.toString() == 'a' * 771
+ @groovy.transform.CompileStatic
+ class X {
+ static void test() {
+ X x = new X()
+ x.doProcess()
+ }
+ void doProcess() {
+ def str = " hello world "
+ def result = process(str)
+ assert result == "hello world"
+ }
+ def process(str) {
+ def result =
str?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()?.trim()
[...]
+ return result
+ }
+ }
+ X.test()
'''
}
}