[
https://issues.apache.org/jira/browse/GROOVY-11379?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-11379:
---------------------------------
Language: groovy
> Use of findAll produces NoSuchMethodError when compiling with Groovy 3.0.21
> and running on an older version
> -----------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-11379
> URL: https://issues.apache.org/jira/browse/GROOVY-11379
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 3.0.12
> Reporter: Sterling Greene
> Priority: Major
>
> This was reported as a regression in Gradle, but I've reduced it down to
> something in Groovy.
> Given this class:
> {code}
> @groovy.transform.CompileStatic
> class Main {
> static void main(String[] args) {
> println "example".split("m").findAll { true }.collect()
> }
> }
> {code}
> If this is compiled with Groovy 3.0.21 and then run with Groovy before 3.0.21
> (tried 3.0.17 and 3.0.20), you'll get a NoSuchMethodError:
> {quote}
> java.lang.NoSuchMethodError: 'java.util.List
> org.codehaus.groovy.runtime.DefaultGroovyMethods.findAll(java.lang.Object[],
> groovy.lang.Closure)'
> at Main.main(Main.groovy:4)
> {quote}
> This might be related to the backport of GROOVY-7001:
> https://github.com/apache/groovy/commit/d9fbe95b47c16502952c1844febd11e789ab8bb4
> I'm not sure if findAll is the only method affected. Compiling with 3.0.20
> and running with 3.0.21 works.
> The bytecode produced with 3.0.21 definitely has a reference to the missing
> method:
> {noformat}
> public static void main(java.lang.String...);
> Code:
> 0: ldc #2 // class Main
> 2: ldc #30 // String example
> 4: ldc #32 // String m
> 6: invokevirtual #38 // Method
> java/lang/String.split:(Ljava/lang/String;)[Ljava/lang/String;
> 9: new #40 // class Main$_main_closure1
> 12: dup
> 13: ldc #2 // class Main
> 15: ldc #2 // class Main
> 17: invokespecial #43 // Method
> Main$_main_closure1."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
> 20: invokestatic #49 // Method
> org/codehaus/groovy/runtime/DefaultGroovyMethods.findAll:([Ljava/lang/Object;Lgroovy/lang/Closure;)Ljava/util/List;
> 23: invokestatic #53 // Method
> org/codehaus/groovy/runtime/DefaultGroovyMethods.collect:(Ljava/lang/Iterable;)Ljava/util/List;
> 26: invokestatic #56 // Method
> org/codehaus/groovy/runtime/DefaultGroovyMethods.println:(Ljava/lang/Object;Ljava/lang/Object;)V
> 29: aconst_null
> 30: pop
> 31: return
> {noformat}
> The same code built with 3.0.20 produces:
> {noformat}
> public static void main(java.lang.String...);
> Code:
> 0: ldc #2 // class Main
> 2: ldc #30 // String example
> 4: ldc #32 // String m
> 6: invokevirtual #38 // Method
> java/lang/String.split:(Ljava/lang/String;)[Ljava/lang/String;
> 9: ldc #40 // class "[Ljava/lang/Object;"
> 11: invokestatic #46 // Method
> org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
> 14: checkcast #40 // class "[Ljava/lang/Object;"
> 17: new #48 // class Main$_main_closure1
> 20: dup
> 21: ldc #2 // class Main
> 23: ldc #2 // class Main
> 25: invokespecial #51 // Method
> Main$_main_closure1."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
> 28: invokestatic #57 // Method
> org/codehaus/groovy/runtime/DefaultGroovyMethods.findAll:([Ljava/lang/Object;Lgroovy/lang/Closure;)Ljava/util/Collection;
> 31: invokestatic #61 // Method
> org/codehaus/groovy/runtime/DefaultGroovyMethods.collect:(Ljava/lang/Iterable;)Ljava/util/List;
> 34: invokestatic #64 // Method
> org/codehaus/groovy/runtime/DefaultGroovyMethods.println:(Ljava/lang/Object;Ljava/lang/Object;)V
> 37: aconst_null
> 38: pop
> 39: return
> {noformat}
> Note that the return type is different for findAll.
> I didn't check if this affected 4.x or 5.x in some way.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)