Grails 2.2.2 Compilation Errors: ThreadGroupContext beaninfo - grails

I am using Grails 2.2.2 with GGTS 3.3M1. When I run my app (grails run-app) and change something in a groovy file then Grails recompiles the file. During this process the following error output occurs:
| Error Unexpected problem clearing ThreadGroupContext beaninfo:
| Error java.lang.ClassCastException: java.beans.WeakIdentityMap cannot be cast to java.util.Map
| Error at org.springsource.loaded.agent.JVMPlugin.reloadEvent(JVMPlugin.java:77)
| Error at org.springsource.loaded.TypeRegistry.fireReloadEvent(TypeRegistry.java:1594)
| Error at org.springsource.loaded.ReloadableType.loadNewVersion(ReloadableType.java:396)
| Error at org.springsource.loaded.TypeRegistry.loadNewVersion(TypeRegistry.java:805)
| Error at org.springsource.loaded.agent.ReloadableFileChangeListener.fileChanged(ReloadableFileChangeListener.java:51)
| Error at org.springsource.loaded.agent.Watcher.determineChangesSince(FileSystemWatcher.java:218)
| Error at org.springsource.loaded.agent.Watcher.run(FileSystemWatcher.java:205)
| Error at java.lang.Thread.run(Thread.java:722)
Reloading: JVMPlugin: warning: unable to clear BEANINFO_CACHE, cant find field
The compilation seems to work fine but the error still occurs.

This is because you are on JDK 1.7 update 21. Something 'moved' in the JDK at that version and the state clearing logic needs updating in springloaded. This is already fixed in the springloaded codebase but won't be in a new grails version for a little while. Older versions of JDK 1.7 would be fine. You can ignore the message, but it means some state was not cleared when a type was reloaded - and this means it may look like it hasn't reloaded some of the changes you might make to your types.

Related

Getting an error while starting Grails

I get the following error when I start Grails.
java.lang.NullPointerException
at org.grails.cli.GrailsCli.initializeProfile(GrailsCli.groovy:504)
at org.grails.cli.GrailsCli.initializeApplication(GrailsCli.groovy:308)
at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:271)
at org.grails.cli.GrailsCli.main(GrailsCli.groovy:162)
| Error Error occurred running Grails CLI: null
My versions are follows | Grails Version: 3.1.1 | Groovy Version:
2.4.5 | JVM Version: 1.8.0_65
I had a halfbaked grails-app folder in my root folder and hence it was causing issues, once I deleted that, the error went away. I hope this helps people, who see the same issue.

Grails-Camel Plugin won't install or run

Please note: Although this question involves a lib called Apache Camel I really think this is just a question about how modern Grails plugins work.
I am on Grails 2.4.2 here, and I am trying to use Apache Camel with Grails and found the Grails Routing plugin annd cannot even get it to install.
The directions say to install by issuing a grails install-plugin routing. When I do this I get:
grails install-plugin routing
Starting process on LT-IE-ZH/10.10.99.14
Loading Grails 2.4.2
|Configuring classpath
.
|Environment set to development
......Warning
|
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Example:
grails.project.dependency.resolution = {
...
plugins {
compile ":routing:1.3.2"
}
}
So I modify my BuildConfig.groovy like so:
plugins {
// plugins for the build system only
build ":tomcat:7.0.54"
compile ":routing:1.3.2"
...lots of other stuff omitted for brevity
}
Then the plugin says to create routes, issue a grails create-route <RouteName>. So I do exactly that:
grails create-route OrderListener
Starting process on LT-IE-ZH/10.10.99.14
Loading Grails 2.4.2
|Configuring classpath
|Running pre-compiled script
|Script 'CreateRoute' not found, did you mean:
1) CreateFilters
2) CreatePom
3) CreateApp_
4) CreateController
5) CreateHibernateCfgXml
Please make a selection or enter Q to quit:
What is going on here?!? How do I install/use this plugin?!? Am I losing my mind, or does this plugin simply not work?
Update
I run grails clean-all, then grails refresh-dependencies then grails create-route OrderListener and I get:
Loading Grails 2.4.2
.
|Environment set to development
.....Error
|
groovy.lang.MissingMethodException: No signature of method: CreateRoute.createArtifact() is applicable for argument types: () values: []
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
Error |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Error |
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
Error |
<huge stacktrace omitted>
Error |
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
Error |
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:68)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
Error |
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
Error |
... 68 more
Whenever you make a change in BuildConfig.groovy be sure to run grails compile to trigger dependency resolution, which will download new and updated plugins and jars, and it will also compile your code which helps to ensure that things are minimally compatible at least.
But the core issue here is that the plugin's CreateRoute.groovy script is badly broken. It's missing an important include and doesn't come close to calling createArtifact correctly. As a workaround until the authors get this fixed, create a script in your app's scripts folder called CreateCamelRoute.groovy with this content:
includeTargets << grailsScript('_GrailsCreateArtifacts')
target(createCamelRoute: "Creates a new Camel Route.") {
createArtifact(type: 'Route', path: 'grails-app/routes', name: argsMap.params?.get(0) ?: 'Example', suffix: 'Route')
}
setDefaultTarget(createCamelRoute)
It's intentionally named differently from the original because if Grails finds two with the same name it asks which one to use. This way you can just run
grails create-camel-route com.foo.bar.OrderListener
and it will work. Note that I changed the example a bit to include a package - always use packages :)

Tests succeed if run from eclipse (STS) but error if run from grails with ClassNotFoundException

I'm getting different test results when run from eclipse (STS) and from grails.
Under grails my tests error (ie dont even run) with a ClassNotFoundException
In eclipse they run successfully.
(And run-app still works fine when run from grails FWIW.)
Tests had been working in both environments for several days.
Then I deleted a number of files I didn't need (domains. controllers and the unit tests on them)
Now I have a problem.
Versions:
ubuntu 10.04
eclipse
eclipse / SpringToolSuite 3.4.0
- groovy compiler: groovy 2.07
- grails location: /home/nick/grails-2.3.6
- JDK compliance level 1.6
- JAVA_HOME=/usr/lib/jvm/java-6-openjdk
grails 2.3.6
- GRAILS_HOME=/home/nick/grails-2.3.6
- JAVA_HOME=/usr/lib/jvm/java-6-openjdk
eclipse / SpringToolSuite 3.4.0
Everything is still fine and dandy from inside eclipse / STS
select project
run as > junit test
runs 24 tests in 3 test classes
all succeed
grails 2.3.6
But from inside grails in a terminal the tests no longer run.
grails> test-app
| Compiling 2 source files.
| Error Fatal error running tests: Could not load class in test type 'unit' (Use --stacktrace to see the full trace)
| Compiling 2 source files..
| Tests FAILED - view reports in /home/nick/grails-2.3.6-workspace/imca2/target/test-reports
Browsing the test-reports shows: No tests executed.
Adding --stacktrace makes no difference, no stacktrace is provided and it still advises me to add --stacktrace.
grails test-app --stacktrace | tee /tmp/out
gives
| Loading Grails 2.3.6
| Configuring classpath
| Configuring classpath.
| Environment set to test
| Environment set to test.
| Environment set to test..
| Environment set to test...
| Environment set to test....
| Environment set to test.....
| Running without daemon...
| Compiling 1 source files
| Compiling 1 source files.
| Error Fatal error running tests: Could not load class in test type 'unit' (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.RuntimeException: Could not load class in test type 'unit'
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
Caused by: java.lang.ClassNotFoundException: com.ubergen.AdvocacyStaffSpec
... 5 more
| Error Fatal error running tests: Could not load class in test type 'unit'
| Compiling 1 source files..
| Tests FAILED - view reports in /home/nick/grails-2.3.6-workspace/imca2/target/test-reports
| Error Error running forked test-app: Could not load class in test type 'unit' (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.RuntimeException: Could not load class in test type 'unit'
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1254)
Caused by: java.lang.ClassNotFoundException: com.ubergen.AdvocacyStaffSpec
... 5 more
| Error Error running forked test-app: Could not load class in test type 'unit'
| Error Forked Grails VM exited with error
I've tried grails clean and clean-all first. test-app then recompiles everything, but it makes no difference - eclipse still runs the tests successfully and grails still errors without running any of them; and it doesn't matter which order I run them in.
Nor does it make any difference which order I run tests in.
What should I do?
In case it helps anyone, I'm posting my own answer after tracking problem down.
As the stacktrace showed only one of the spock tests. Grails could run the others successfully.
On closer inspection the failing test turned out to have a mistyped class name. I hadn't looked closely enough as its name is only a convention, or so I thought.
So, assuming there is a class CorrectName that needs testing but the test is mistyped as WrongNameSpec instead of CorrectNameSpec...
Here is the mistyped test code in CorrectName.groovy:
[snip]
#TestFor(CorrectName)
class WrongNameSpec extends Specification {
[snip]
This runs in eclipse/STS and tests the CorrectName class successfully.
In grails it fails with a stacktrace that says:
| Error Fatal error running tests: Could not load class in test type 'unit'
Caused by: java.lang.ClassNotFoundException: com.ubergen.CorrectNameSpec
Grails and eclipse have different target areas to put the compiled code in. Here the class files are:
./target-eclipse/classes/com/ubergen/WrongNameSpec.class
./target/test-classes/unit/com/ubergen/WrongNameSpec.class
As the stack trace said, there is no CorrectNameSpec class.
This is the corrected code and runs ok in both:
[snip]
#TestFor(CorrectName)
class CorrectName extends Specification {
[snip]
Grails is doing something like building a list of tests from the #TestFor but assuming the test classname will follow the expected convention.
Summary:
In eclipse/sts the name of the unit test is a convention, its the #TestFor that matters. In grails the name of the unit test is not just a convention, you must name it as expected, because grails will assume there is a class file that matches that name and you will get a ClassNotFoundException.

Grails 2.0 and PayPal plugin

I've installed the newest Grails PayPal-Plugin (0.6.4) and got the following error:
Problems occurred (un)installing plugins. See details for more information
------System.out:-----------
| Loading Grails 2.0.0
| Configuring classpath.
| Environment set to development.....
| Compiling 97 source files
| Compiling 97 source files.
| Error Compilation error: startup failed:
C:\Users\username\.grails\2.0.0\projects\projectname\plugins\paypal-0.6.4\grails-app\controllers\org\grails\paypal\PaypalController.groovy: -1: The return type of java.lang.Object notify() in org.grails.paypal.PaypalController is incompatible with void notify() in java.lang.Object
. At [-1:-1] # line -1, column -1.
1 error
------System.err:-----------
I fixed it by renaming notify() into notifyPaypal() => Error PayPal plugin on grails 2.0.0.RC3
But the plugin seems to disturb springSecurity because I got the following error if I try to login:
| Error 2012-02-05 21:42:07,245 ["http-bio-8080"-exec-8] ERROR [/projectname].[default] - Servlet.service() for servlet [default] in context with path [/projectname] threw exception
Message: The specified user domain class 'Person' is not a domain class
How can I fix it?
Notice that two versions have been released since 0.6.4, and it now behaves as you asked regarding the 'notify()' method (probably thanks to your report).
http://grails.org/plugin/paypal/
(just saying it here for any casual reader to know)

grails startup error when run-app

When I copied my old project from my old computer and typed grails run-app in project folder, I get the following error:
| Error Compilation error: startup failed:
G:\Windows NT 5.0 Workstation Profile\.grails\2.0.0\projects\timesheet\plugins\g
orm-labs-0.8.5\src\groovy\GormLabsHibernateCriteriaBuilder.groovy: 35: The retur
n type of java.lang.Object order(java.lang.String) in grails.orm.GormLabsHiberna
teCriteriaBuilder is incompatible with org.grails.datastore.mapping.query.api.Cr
iteria order(java.lang.String) in grails.orm.HibernateCriteriaBuilder
. At [35:5] # line 35, column 5.
Object order(String propertyName) {
^
1 error
Can anyone tell me what this relates to?
Thanks
You said you just copied the project, but you must have at least partially upgraded it since your error shows that you're using Grails 2.0.0. The error message has to do with the Gorm Labs plugin, which has been abandoned for over a year and is unlikely to be compatible with newer versions of Grails. I'd remove that and any usage of it and see where you get from there.

Resources