groovy

Actual ClassNotFoundException is hidden when loading classes with GCL

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.0-JSR-5
  • Fix Version/s: 1.0-JSR-6
  • Component/s: groovy-jdk
  • Labels:
    None
  • Number of attachments :
    0

Description

When loading a class through the GroovyClassLoader the actual class which is not found is hidden when a ClassNotFoundException occurs in a parent class.

I discovered this in grails when loading test cases. Test cases extend GroovyTestCase the exception thrown is:

ClassNotFoundException: GroovyTestCase

But the actual reason was that junit.jar was not on the classpath and hence GroovyTestCase could not be loaded as it referenced the junit classes.

This is very mysterious and difficult to debug and needs fixing

Activity

Hide
blackdrag blackdrag added a comment -

any suggestion how to write a testcase for that?

Show
blackdrag blackdrag added a comment - any suggestion how to write a testcase for that?
Hide
Graeme Rocher added a comment -

Hmm its a tricky one, I encountered it when junit.jar was not on the classpath. Maybe create a groovy class that extends some imaginary class that isn't on the classpath.

Then extend that class with another class (ie 3 levels of inheritance with the top level being a non-existent class).

Then try and load the class at the bottom of the tree and make sure it reports that the missing class is the imaginary class. if that makes sense?

Show
Graeme Rocher added a comment - Hmm its a tricky one, I encountered it when junit.jar was not on the classpath. Maybe create a groovy class that extends some imaginary class that isn't on the classpath. Then extend that class with another class (ie 3 levels of inheritance with the top level being a non-existent class). Then try and load the class at the bottom of the tree and make sure it reports that the missing class is the imaginary class. if that makes sense?
Hide
blackdrag blackdrag added a comment -

if I extend a class that is not on the classpath, then the compilation will fail. I would need a precompiled class that lacks a parent... hmm.. maybe.. maybe I should create a ClassLoader without parent, that is missing junit but will compile a GroovyTestcase... that is nearly the same as your description above... downside of this is, that I will have to go through the urls and look at the jars there to remove the junit jar... that's a fragile mechanism I think... but better than nothing.

Show
blackdrag blackdrag added a comment - if I extend a class that is not on the classpath, then the compilation will fail. I would need a precompiled class that lacks a parent... hmm.. maybe.. maybe I should create a ClassLoader without parent, that is missing junit but will compile a GroovyTestcase... that is nearly the same as your description above... downside of this is, that I will have to go through the urls and look at the jars there to remove the junit jar... that's a fragile mechanism I think... but better than nothing.
Hide
blackdrag blackdrag added a comment -

ok, it seems it is possible to test it this way. It will cause a NoClassDefFoundError, because the TestCase class is not found. So it is as it should be

Show
blackdrag blackdrag added a comment - ok, it seems it is possible to test it this way. It will cause a NoClassDefFoundError, because the TestCase class is not found. So it is as it should be

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: