groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Theodorou (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-7443) instantiating a class withTraits does not use the classloader of the trait
Date Wed, 03 Jun 2015 06:34:49 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-7443?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jochen Theodorou updated GROOVY-7443:
-------------------------------------
    Description: 
this fails:
def aWithB = new ClassA().withTraits(traitB)
when traitB is not from the classloader of class A.

full example code:
{code:Java}
package groovy.lang.traits

import org.codehaus.groovy.control.CompilerConfiguration;

class GroovyTraitsClassloaderTest {

	static class ClassA {
		
	}
	
	static trait TraitA {
		
		def aMethod() {
			println "traitA method"
		}
		
	}
	
	static main(args) {
	
		
		def aWithA = new ClassA().withTraits(TraitA)
		
		aWithA.aMethod()
		
		
		GroovyClassLoader gcl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
		
		Class classB = gcl.parseClass("""\
class ClassB {}
""")
		
		Class traitB = gcl.parseClass("""\
trait TraitB {
	
	def bMethod() {
		println "traitB method"
	}
	
}
""")
		
		//ok
		def bWithA = classB.newInstance().withTraits(TraitA)

		//ok
		def bWithB = classB.newInstance().withTraits(traitB)
		bWithB.bMethod()
		
		//fails
		def aWithB = new ClassA().withTraits(traitB)
		
		aWithB.bMethod()
		
		
	}

}
{code}

  was:
this fails:
def aWithB = new ClassA().withTraits(traitB)
when traitB is not from the classloader of class A.

full example code:
<code>
package groovy.lang.traits

import org.codehaus.groovy.control.CompilerConfiguration;

class GroovyTraitsClassloaderTest {

	static class ClassA {
		
	}
	
	static trait TraitA {
		
		def aMethod() {
			println "traitA method"
		}
		
	}
	
	static main(args) {
	
		
		def aWithA = new ClassA().withTraits(TraitA)
		
		aWithA.aMethod()
		
		
		GroovyClassLoader gcl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
		
		Class classB = gcl.parseClass("""\
class ClassB {}
""")
		
		Class traitB = gcl.parseClass("""\
trait TraitB {
	
	def bMethod() {
		println "traitB method"
	}
	
}
""")
		
		//ok
		def bWithA = classB.newInstance().withTraits(TraitA)
		
		//ok
		def bWithB = classB.newInstance().withTraits(traitB)
		bWithB.bMethod()
		
		//fails
		def aWithB = new ClassA().withTraits(traitB)
		
		aWithB.bMethod()
		
		
	}

}

</code>


> instantiating a class withTraits does not use the classloader of the trait
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-7443
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7443
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.3.7, 2.4.3
>         Environment: jvm 1.7, MaxOSX
>            Reporter: Marc Hadfield
>              Labels: class-generation, traits, usertask
>         Attachments: GroovyTraitsClassloaderTest.groovy
>
>
> this fails:
> def aWithB = new ClassA().withTraits(traitB)
> when traitB is not from the classloader of class A.
> full example code:
> {code:Java}
> package groovy.lang.traits
> import org.codehaus.groovy.control.CompilerConfiguration;
> class GroovyTraitsClassloaderTest {
> 	static class ClassA {
> 		
> 	}
> 	
> 	static trait TraitA {
> 		
> 		def aMethod() {
> 			println "traitA method"
> 		}
> 		
> 	}
> 	
> 	static main(args) {
> 	
> 		
> 		def aWithA = new ClassA().withTraits(TraitA)
> 		
> 		aWithA.aMethod()
> 		
> 		
> 		GroovyClassLoader gcl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
> 		
> 		Class classB = gcl.parseClass("""\
> class ClassB {}
> """)
> 		
> 		Class traitB = gcl.parseClass("""\
> trait TraitB {
> 	
> 	def bMethod() {
> 		println "traitB method"
> 	}
> 	
> }
> """)
> 		
> 		//ok
> 		def bWithA = classB.newInstance().withTraits(TraitA)
> 		//ok
> 		def bWithB = classB.newInstance().withTraits(traitB)
> 		bWithB.bMethod()
> 		
> 		//fails
> 		def aWithB = new ClassA().withTraits(traitB)
> 		
> 		aWithB.bMethod()
> 		
> 		
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message