Note that there are some explanatory texts on larger screens.

plurals
  1. POError using classloader to load groovy class
    primarykey
    data
    text
    <p>I am attempting to load a groovy class by name using a classloader, and the class fails to load in the case that the class has a reference to a static inner class in another class.</p> <p>Inside my groovy class I have the following:</p> <pre><code>def classLoader = getClass().classLoader try { classLoader.loadClass( "com.test.TestClass" ) } catch(Throwable e) { Sigil.logger.error("Error loading class: $it &gt;&gt; ${e.message}", e) } </code></pre> <p>In the above, my groovy file TestClass has a static inner class inside it, that extends a static inner class of another file. When I try to run the above code I get the message:</p> <pre><code>ERROR [05 Aug 2013 06:53:28,851] (invoke0:?) - Error loading class: com.test.TestClass &gt;&gt; startup failed: unable to resolve class UserValidity.Validator @ line 85, column 5. public static class Validator extends UserValidity.Validator{ ^ 1 error </code></pre> <p>Has anyone come across any problems dealing with static inner classes and class loading in groovy before? The classes all compile correctly and unit tests run etc. I would have thought that when I try to load the class TestClass explicitly in my classloader, it would also load the other necessary classes from the source tree as needed?</p> <hr> <p><strong>UPDATE:</strong></p> <p>Here is a snippet of the class that is failing to load:</p> <pre><code>class TestClass{ //... Other normal class stuff here public static class Validator extends UserValidity.Validator @Override def validate(u) { def result = super.validate(u) if(!u.valid ){ result += [isValid:false] } result } } } </code></pre> <p>And this fails as it says it cannot resolve the reference to the UserValidity.Validator, which is also pretty simple:</p> <pre><code>class UserValidity { //normal class stuff here public static class Validator { def validate(u){ //do validation stuff result } } } </code></pre> <p>Both are just regular groovy classes.</p> <hr> <p><strong>UPDATE 2:</strong></p> <p>If I extract the static inner class <code>UserValidity.Validator</code> out in to a standalone class, and just extend that with the static inner class in <code>TestClass</code> then it appears to work, so definitely seems to be some issue with the parent of the inner class being another inner class</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload