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

paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 94ae84d3fa GROOVY-12009: StringGroovyMethods#stripIndent(boolean) 
doesn't handle non-String cases as advertised
94ae84d3fa is described below

commit 94ae84d3fa788065b04d6d423e9551f6d35c8b8b
Author: Paul King <[email protected]>
AuthorDate: Fri May 15 10:31:40 2026 +1000

    GROOVY-12009: StringGroovyMethods#stripIndent(boolean) doesn't handle 
non-String cases as advertised
---
 .../org/codehaus/groovy/runtime/StringGroovyMethods.java | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 2f4f215c82..e973cef402 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -21,7 +21,6 @@ package org.codehaus.groovy.runtime;
 import groovy.lang.Closure;
 import groovy.lang.EmptyRange;
 import groovy.lang.GString;
-import groovy.lang.GroovyRuntimeException;
 import groovy.lang.IntRange;
 import groovy.lang.Range;
 import groovy.transform.stc.ClosureParams;
@@ -36,9 +35,6 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
 import java.io.Writer;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -3221,23 +3217,17 @@ public class StringGroovyMethods extends 
DefaultGroovyMethodsSupport {
 
     /**
      * Same logic as {@link #stripIndent(CharSequence)} if {@code 
forceGroovyBehavior} is {@code true},
-     * otherwise Java 13's {@code stripIndent} will be invoked.
+     * otherwise {@code stripIndent} from JDK 13+ will be invoked.
      *
      * @param self The CharSequence to strip the leading spaces from
-     * @param forceGroovyBehavior force groovy behavior to avoid conflicts 
with Java13's stripIndent
+     * @param forceGroovyBehavior force groovy behavior to avoid conflicts 
with Java stripIndent
      *
      * @since 3.0.0
      */
     @Incubating
     public static String stripIndent(final CharSequence self, final boolean 
forceGroovyBehavior) {
         if (!forceGroovyBehavior) {
-            try {
-                MethodHandle mh = 
MethodHandles.lookup().findVirtual(self.getClass(), "stripIndent", 
MethodType.methodType(String.class));
-                return (String) mh.bindTo(self).invokeWithArguments();
-            } catch (NoSuchMethodException | IllegalAccessException ignored) {
-            } catch (Throwable t) {
-                throw new GroovyRuntimeException(t);
-            }
+            return self.toString().stripIndent();
         }
 
         return stripIndent(self);

Reply via email to