david_beutel
11/20/2024, 8:50 AMConfigSlurper
defaults to using a new GroovyClassLoader()
, which uses Thread.currentThread().getContextClassLoader()
as its parent. That results in the following MissingMethodException
, if the Script
class was loaded by a different ClassLoader
, e.g., by running the following example script:
def ct = Thread.currentThread()
def originalCCL = ct.contextClassLoader
def newCL = new URLClassLoader(originalCCL.parent.parent.URLs, (ClassLoader) null)
def gls = 'groovy.lang.Script'
assert originalCCL.loadClass(gls) != newCL.loadClass(gls)
ct.contextClassLoader = newCL
def config = new ConfigSlurper().parse('foo = 42')
Caught: groovy.lang.MissingMethodException: No signature of method: groovy.util.ConfigSlurper.parse() is applicable for argument types: (Script_35210c81fc1d6f48d278c8cf2137664d) values: [Script_35210c81fc1d6f48d278c8cf2137664d@4c6daf0]
Possible solutions: parse(groovy.lang.Script), parse(java.lang.Class), parse(java.lang.String), parse(java.net.URL), parse(java.util.Properties), parse(groovy.lang.Script, java.net.URL)
Is that the intended behavior? The new ConfigSlurper().classLoader
can be overridden, but would it be better to default it to new GroovyClassLoader(this.class.classLoader)
?bsdooby
12/01/2024, 10:06 AMvar str = buildString {
append("Hi")
append(" ")
append("there)
}
What is the equivalent, or can this be “emulated” or written directly in Groovy? See https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/build-string.htmlPoundex
12/01/2024, 11:00 AMStringBuilder sb = new StringBuilder()
sb << "Hi"
sb << " "
sb << "there"
String str = sb.toString()
If you want something closer to the Kotlin thing one way of doing it might be:
String buildString(@DelegatesTo(StringBuilder) Closure<?> fn) {
StringBuilder sb = new StringBuilder()
fn.delegate = sb
fn()
return sb.toString()
}
String str = buildString {
append("Hi")
append(" ")
append("there")
}
bsdooby
12/01/2024, 4:13 PMbsdooby
12/01/2024, 4:13 PMmatrei
12/02/2024, 7:41 AMdef str = new StringBuilder().with {
append('Hi')
append(' ')
append('there')
}.toString()
bsdooby
12/02/2024, 8:41 AMwith
entails)glaforge
12/02/2024, 9:41 AMLing Hengqian
12/05/2024, 11:19 AMsbglasius
12/06/2024, 2:48 PMsolvingj
12/09/2024, 2:02 PM06:45:39 java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: org.mongodb#mongodb-driver-core;3.8.2: java.util.ConcurrentModificationException at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1043)]
solvingj
12/09/2024, 2:04 PMinitClass=false
option might solve this problem? What might the side effects of this flag be?solvingj
12/13/2024, 3:22 PMVampire
12/27/2024, 1:17 AMJames Daugherty
01/06/2025, 3:07 PMmatrei
01/20/2025, 10:21 PM@Delegate
annotation, for example:
static GebTestManager testManager
@Delegate
Browser getBrowser() {
testManager.browser
}
(Browser is a Groovy class from Geb 6.0 library).
I am not managing to get the original parameter names into the generated delegation methods from Browser
. For example, for `Browser.go(String url)`the following is generated:
@Generated
public void go(String param0) {
CallSite[] var2 = $getCallSiteArray();
var2[307].call(var2[308].callCurrent(this), param0);
}
Is there a way to help the compiler retain the original parameter name?
I have tried (with variations and combinations of) the following in the Gradle build script:
tasks.withType(GroovyCompile).configureEach {
options.debug = true
options.compilerArgs << '-parameters'
groovyOptions.parameters = true
groovyOptions.optimizationOptions['parameters'] = true
}
I'm using Groovy 3.0.23 and Java 11.Gianluca Sartori
01/27/2025, 3:43 PMsecurityService
has a method called isLoggedIn()
.
if (securityService.loggedIn) {
to make it work I need to call the getter explicitly:
if (securityService.isLoggedIn()) {
Is there a reason for it?Gianluca Sartori
01/27/2025, 4:03 PMBoolean
it has to return a boolean
. Is this behaviour somehting we want from Groovy or it is a bug?bsdooby
01/27/2025, 11:02 PMVampire
03/04/2025, 2:58 AMbinExpr.getRightExpression()
by new MethodCallExpression(binExpr.getRightExpression(), "iterator", new EmptyExpression())
but now I get during "Class Generation" phase
Unable to produce AST for this phase due to an error:
BUG! exception in phase 'class generation' in source unit 'script1741057086260.groovy' Error while popping argument from operand stack tracker in class Foo method java.lang.Object $spock_feature_0_0prov0().
Fix the above error(s) and then press RefreshAny idea why I get this or how to investigate?
Jeremy Schroeder
03/15/2025, 1:59 AMJuho Naalisvaara
04/04/2025, 6:51 AMThomas Rasmussen
04/14/2025, 5:04 PM$ sdk use groovy 3.0.24
Using groovy version 3.0.24 in this shell.
$ groovy
/usr/bin/env: 'sh\r': No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
Tested on MacOs and LinuxJuho Naalisvaara
04/16/2025, 2:01 PMSean Williams
04/29/2025, 11:00 PM@WithPlugin()
, which (according to the SR docs) adds a named Jira plugin's ClassLoader to (much to our chagrin) the root ClassLoader for all scripts (versus the annotated one).
One of the plugins we're doing this with ships a really old version of Apache commons-csv (we're not even using it ourselves, but I guess it's in their dependency chain), whereas another one of our scripts (not using @WithPlugin()
) fetches a more recent version from maven-central via @Grab()
. The older version isn't forwards-compatible due methods added in more recent versions.
I'm still pretty new to Groovy - in .NET, we have AssemblyLoadContexts, binding redirects, and other tools to alleviate problems like these. Searching "parent-last classloader" seems to get a lot of responses for Java proper, but it's not clear if that's:
• applicable to Groovy
• safe to do
• already implemented with prior art
Can someone help me understand what I'm missing?Vampire
05/08/2025, 10:56 AMgroovy.lang.MissingMethodException: No signature of method: geb.navigator.DefaultNavigator.ensureContainsAtMostSingleElement() is applicable for argument types: (String) values: [text]
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//geb.navigator.DefaultNavigator.methodMissing(DefaultNavigator.groovy:811)
at java.base@11.0.24/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@11.0.24/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base@11.0.24/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@11.0.24/java.lang.reflect.Method.invoke(Method.java:566)
at app//org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
at app//groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:924)
at app//groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1413)
at app//groovy.lang.MetaClassImpl.doInvokeMethod(MetaClassImpl.java:1335)
at app//groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1088)
at app//groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1142)
at app//groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1007)
at app//groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:165)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//geb.navigator.DefaultNavigator.text(DefaultNavigator.groovy:622)
at java.base@11.0.24/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@11.0.24/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base@11.0.24/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@11.0.24/java.lang.reflect.Method.invoke(Method.java:566)
at app//org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:343)
at app//groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:328)
at app//groovy.lang.MetaClassImpl.doInvokeMethod(MetaClassImpl.java:1333)
at app//groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1088)
at app//groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1142)
at app//groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1007)
at app//groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:165)
at app//org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:321)
at app//geb.junit5.ParallelExecutionTest.testRunningIterationsInParallel(ParallelExecutionTest.groovy:90)
at java.base@11.0.24/java.lang.reflect.Method.invoke(Method.java:566)
at java.base@11.0.24/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base@11.0.24/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base@11.0.24/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base@11.0.24/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base@11.0.24/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
The code is this: https://github.com/apache/groovy-geb/blob/fc4130b3f190d9a98f4ba0bddad2d03fe64733b3[…]/geb-core/src/main/groovy/geb/navigator/DefaultNavigator.groovy
So the code at line 622 is calling the method in line 854.
So to my understanding it should not even go to methodMissing
but directly invoke the method.paulk_asert
05/08/2025, 11:07 AMVampire
05/08/2025, 11:39 AMVampire
05/08/2025, 11:40 AMVampire
05/09/2025, 1:43 PM