groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Denis Jouvin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8227) Allow to specify Groovysh (and GroovyShell) class loader different from TCCL
Date Tue, 13 Jun 2017 08:41:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16047576#comment-16047576
] 

Denis Jouvin commented on GROOVY-8227:
--------------------------------------

Here is a small script that illustrate the problem :

{code}
import org.codehaus.groovy.tools.shell.Groovysh
import org.codehaus.groovy.tools.shell.IO

/** Simple delegating class loader printing out the loaded classes */
class VerboseClassLoader extends ClassLoader {
	VerboseClassLoader(ClassLoader parent) { super(parent) }
	@Override Class<?> loadClass(String name) throws ClassNotFoundException {
		println name
		super.loadClass name
	}
}

def cl = this.class.classLoader // default class loader
def tccl = Thread.currentThread().contextClassLoader // Thread context class loader (same?)

// We set our verbose class loader as TCCL to check if the TCCL is used
Thread.currentThread().contextClassLoader = new VerboseClassLoader(tccl)

// Now, we instanciate a new Groovysh specifying the class loader we want to use
// if this class loader is propagated correctly, there should be no output
def sh = new Groovysh(cl, new Binding(), new IO())
sh.run(null)
{code}

Unfortunately we see in the output:

{noformat}
org.codehaus.groovy.tools.shell.IOBeanInfo
org.codehaus.groovy.tools.shell.IOCustomizer
org.codehaus.groovy.tools.shell.GroovyshBeanInfo
org.codehaus.groovy.tools.shell.ShellBeanInfo
org.codehaus.groovy.tools.shell.ShellCustomizer
org.codehaus.groovy.tools.shell.GroovyshCustomizer
org.codehaus.groovy.tools.shell.util.MessageSourceBeanInfo
org.codehaus.groovy.tools.shell.util.MessageSourceCustomizer
groovy.lang.ReferenceBeanInfo
groovy.lang.ReferenceCustomizer
groovy.lang.Closure$1BeanInfo
groovy.lang.ClosureBeanInfo
groovy.lang.ClosureCustomizer
groovy.lang.Closure$1Customizer
org.codehaus.groovy.tools.shell.util.LoggerBeanInfo
org.codehaus.groovy.tools.shell.util.LoggerCustomizer
org.codehaus.groovy.tools.shell.CommandRegistryBeanInfo
org.codehaus.groovy.tools.shell.CommandRegistryCustomizer
java.util.TreeSetBeanInfo
java.util.AbstractSetBeanInfo
(..)
{noformat}


> Allow to specify Groovysh (and GroovyShell) class loader different from TCCL
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-8227
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8227
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime, Groovysh
>    Affects Versions: 2.4.x, 2.5.x
>         Environment: OSGi (Karaf 2.x, 3.X or 4.x)
>            Reporter: Denis Jouvin
>              Labels: classloader, groovysh, groovyshell
>             Fix For: 2.4.x, 2.5.x
>
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> Allthough the Groovy API seem to allow one to specify the class loader when instanciating
a Groovysh or GroovyShell, internally in some places Groovy will silently use the TCCL (thread
context class loader) and there is no way to avoid that without hacking Groovy and chasing
all the places where {{getThreadContextClassLoader()}} is used.
> This is problematic, especially in OSGi environement, since the TCCL is not compatible
with OSGi principles (i.e. every bundle has its own class loader), and also with some modern
modular containers similar to OSGi. When a class loader is specified in the GroovyShell or
Groovysh creation, Groovy should propagate that class loader correctly (or instanciate children
class loader of that specified class loader), and in no way use the TCCL.
> This may be a dupplicate of [Groovy 4895|https://issues.apache.org/jira/browse/GROOVY-4895]



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message