1

I'm using a plugin which has this Service:

 package grails.plugins.imports

 class ImportsService {
     static rabbitQueue = "${grails.util.Holders.grailsApplication.metadata['app.name']}ImportRows"
 ....
 }

While this works fine when using run-app; i.e grails run-app, this is wreaking havoc when attempting to run as a war; grails run-war.

2014-09-09 15:54:25,069 [localhost-startStop-1] ERROR StackTrace - Full Stack Trace:

java.lang.NullPointerException: Cannot get property 'metadata' on null object
    at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:169)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
    at grails.plugins.imports.ImportsService.<clinit>(ImportsService.groovy:9)

Short of forking the plugin, any suggestions here?

Grails 2.3.10

Thanks in advance, Todd

Todd M
  • 1,012
  • 1
  • 15
  • 25
  • I think you or plugin may define the `metadata` in the incorrect `environment` (in `development` for example). Please check the configs. – wwarlock Sep 10 '14 at 07:34
  • check configs for what? Sorry, I'm not following – Todd M Sep 10 '14 at 13:27
  • Ah, I understood. At first I thought Grails couldn't find the `metadata`. But there is the trouble with the `grailsApplication`. I have not ideas for that. – wwarlock Sep 10 '14 at 15:32

1 Answers1

0

So, I know your goal was to avoid forking the plugin, but I think the issue is that the plugin was written in earlier days when you would get the grailsApplication object through a holder class. That's not really recommended these days (see Burt Beckwith's post on the subject), but there are options.

The easiest way for your plugin to get the grailsApplication object would be through dependency injection:

class ImportsService {
    def grailsApplication
    static rabbitQueue = "${grailsApplication.metadata['app.name']}ImportRows"
    //....
}

Though in this case, since all you need is the app.name, it might be better to:

class ImportsService {
    static rabbitQueue = "${grails.util.Metadata.current.'app.name'}ImportRows"
    //....
}

You might try manipulating the plugin code in a local copy to see if that fixes the issue. GGTS makes that fairly easy by providing the plugins in the project explorer view. If that change works, and you can submit a patch to the plugin developer, you might be able to have the fix become part of the official release.

Community
  • 1
  • 1
jonnybot
  • 2,435
  • 1
  • 32
  • 56