[groovy-user] Classloading goes bad ?

27 views
Skip to first unread message

Konstantinos Kostarellis

unread,
Feb 29, 2012, 9:44:12 AM2/29/12
to us...@grails.codehaus.org, us...@groovy.codehaus.org
Evnrionment: 
Groovy Version: 1.8.6 JVM: 1.6.0_26 Vendor: Sun Microsystems Inc. OS: Linux

While the following groovy-script works fine in pure groovy

---------------
@Grab('de.jollyday:jollyday:0.4.6')

import de.jollyday.Holiday
import de.jollyday.HolidayCalendar
import de.jollyday.HolidayManager

HolidayManager hm = HolidayManager.getInstance(HolidayCalendar.GERMANY)

List<Holiday> holidayList = hm.getHolidays(2012, 'he').sort({it.date})

holidayList.each {println it}
---------------

in grails 2.0.1 (tryed also 1.3.7) when I add the dependency to BuildConfig.groovy

                  compile 'de.jollyday:jollyday:0.4.6'

and create a similar Controller Method (or for that sake a Service):
---------------
package jollycheck

import de.jollyday.Holiday
import de.jollyday.HolidayCalendar
import de.jollyday.HolidayManager

class HoliController {

    def index = {

HolidayManager hm = HolidayManager.getInstance(HolidayCalendar.GERMANY)

List<Holiday> holidayList = hm.getHolidays(2012, 'he').sort({it.date})

render holidayList
     }
}
---------------
I get an exception on instantiation time in HolidayManager.getInstance(.....

I guess somehow it is not able to load the XML-Resources provided in the jar.

If i call that code from my JUnit-Test from within STS it works fine, but the same tests fail if
grails test-app is called.

I guess grails somewhat manipulates the classpath, but I don't know what it is exactly,
can someone give me a hint ? 

Thnx,
   Kosta

Cédric Champeau

unread,
Feb 29, 2012, 12:10:44 PM2/29/12
to us...@groovy.codehaus.org
Looks like it's more a question for the Grails mailing list, but just in case, could you paste the exception you have ?
-- 
Cédric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau

Konstantinos Kostarellis

unread,
Mar 1, 2012, 8:39:25 AM3/1/12
to us...@grails.codehaus.org, us...@groovy.codehaus.org
@Cedric yes you are right its more of a grails question :) Strange is thou that the script (almost) works well in pure groovy. It won't exit after its done (won't return to the command-line -> I have to Ctrl+C kill it to get back) don't know why this is happening.
Do you have an why the script won't quit and return to my shell-prompt ?

@Bobby jollydays http://jollyday.sourceforge.net/ is a lib that uses joda-time to calculate holidays based on rules saved in XML files (provided in the libs jar file, no online request needed). I guess it uses jaxb to load those XMLConfigs ("Holidays_${COUNTRYCODE}.xml") but if its used in a grails context it won't find the XMLs. Thou it works if the code is called from within STS in e.g. a JUnit - Test. Same unit-test fails thou when its run in grails interactive shell with test-app.

I didn't include the joda-time grails plugin in my app. Checkout the sample app: It got only the default plugins + the dependency to jollyday.

Basically I was about to write a grails plugin for jollydays and tripped over that problem.

I created a simple grails 2.0.1. sample app demonstrating the problem and I pushed it to github this morning https://github.com/delight/Jollycheck 

The exception happens in

11: HolidayManager hm = HolidayManager.getInstance(HolidayCalendar.GERMANY)

and the stacktrace in grails 2.0.1 looks like this:

| Error 2012-03-01 11:17:24,795 [http-bio-8080-exec-10] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing request: [GET] /Jollycheck/holi/index
Stacktrace follows:
Message: null
   Line | Method
->> 130 | handleClassCastException in javax.xml.bind.ContextFinder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   202 | newInstance              in     ''
|   147 | newInstance . . . . . .  in     ''
|   362 | find                     in     ''
|   446 | newInstance . . . . . .  in javax.xml.bind.JAXBContext
|   409 | newInstance              in     ''
|    89 | createJAXBContext . . .  in de.jollyday.util.XMLUtil
|    67 | unmarshallConfiguration  in     ''
|   283 | init . . . . . . . . . . in de.jollyday.impl.XMLManager
|   156 | createManager            in de.jollyday.HolidayManager
|   117 | getInstance . . . . . .  in     ''
|   101 | getInstance              in     ''
|    11 | index . . . . . . . . .  in jollycheck.HoliController
|   886 | runTask                  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run . . . . . . . . . .  in     ''
^   662 | run                      in java.lang.Thread

####################################################################################
In grails 1.3.7 the error looks like this:

Error 500: Executing action [index] of controller [jollycheck.HoliController] caused exception: Cannot instantiate configuration.
Servlet: grails
URI: /jollycheck/grails/holi/index.dispatch
Exception Message: 
Caused by: 
Class: HoliController 
At Line: [11] 
Code Snippet:

with the following stacktrace:

2012-03-01 14:08:26,911 [http-8080-2] ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [GET] /jollycheck/holi/index
Stacktrace follows:
java.lang.NullPointerException
        at javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:130)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:147)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:362)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409)
        at de.jollyday.util.XMLUtil.createJAXBContext(XMLUtil.java:89)
        at de.jollyday.util.XMLUtil.unmarshallConfiguration(XMLUtil.java:67)
        at de.jollyday.impl.XMLManager.init(XMLManager.java:283)
        at de.jollyday.HolidayManager.createManager(HolidayManager.java:156)
        at de.jollyday.HolidayManager.getInstance(HolidayManager.java:117)
        at de.jollyday.HolidayManager.getInstance(HolidayManager.java:101)
        at de.jollyday.HolidayManager$getInstance.call(Unknown Source)
        at jollycheck.HoliController$_closure1.doCall(HoliController.groovy:11)
        at jollycheck.HoliController$_closure1.doCall(HoliController.groovy)
        at java.lang.Thread.run(Thread.java:662)

2012/2/29 Cédric Champeau <cedric....@gmail.com>

Looks like it's more a question for the Grails mailing list, but just in case, could you paste the exception you have ?

2012/2/29 bobbywarner <bobby...@gmail.com>
I've never used this particular library, but looks like it has the following
dependencies:

com.sun.xml.bind:jaxb-impl:2.2.4
javax.xml.bind:jaxb-api :2.2.4
joda-time:joda-time:2.0
junit:junit:4.8.2

Are you using the JodaTime Grails plugin?  If so, which version of JodaTime
is used by the version of the plugin you are using?


Thanks,
Bobby

--
View this message in context: http://grails.1312388.n4.nabble.com/Classloading-goes-bad-tp4431718p4432388.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Konstantinos Kostarellis

unread,
Mar 1, 2012, 9:22:19 AM3/1/12
to us...@grails.codehaus.org, us...@groovy.codehaus.org
@Bobby I just solved the problem (grails context). I simply had to exclude jaxb-api from the dependency.
Works fine for me now ;)

@Cedric I still don't know why the script "hangs" thou ... this is not really important for me and my future development
but I'm kind of a curious person when it comes to such things. Maybe you got an idea ?

Thank you guys,
   Kosta

2012/3/1 Konstantinos Kostarellis <kosta....@gmail.com>
Reply all
Reply to author
Forward
0 new messages