Grails 2.3.6 Scaffolded index page throws ArrayIndexOutOfBoundsException - grails

I have a grails application which is failing at runtime in a cryptic way
(cyptic to me anyway)
with a ArrayIndexOutOfBoundsException when I visit the scaffolded /imca2/imcaReferral/index.
* now edited to put solution at end *
There are about a dozen domain classes.
I haven't got round to worrying about the UI yet so the controllers are all dynamically scaffolded.
All the other controllers work OK.
This Controller:
package com.ubergen
class ImcaReferralController {
def scaffold = ImcaReferral
}
For this Domain:
package com.ubergen
class ImcaReferral {
private def todayDate = new Date()
String advocacyReferenceNum = ""
[snip a lot of code]
String toString() {
"${this.advocacyReferenceNum}: ${this.client?this.client:'-'}${this.referralIssue?', '+this.referralIssue:''}"
}
}
(I don't want to post the domain class here as its huge).
Produces this stacktrace:
|Server running. Browse to http://localhost:8080/imca2
| Error 2014-03-12 18:48:24,935 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver - ArrayIndexOutOfBoundsException occurred when processing request: [GET] /imca2/imcaReferral/index
0. Stacktrace follows:
Message: 0
Line | Method
->> 55 | <init> in grails.orm.PagedResultList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 15 | $tt__index in com.ubergen.ImcaReferralController
| 191 | doFilter . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run . . . in java.lang.Thread
Cleaning and (re)compiling make no difference.
The domain class is being used during bootstrapping to push data successfully into the database, so it works to that extent.
I can run the application from the command line instead of from inside eclipse/STS. The same error is thrown.
run-app --noreloading makes no difference either (clutching at straws now). And run-war also produces the same error.
run-app --verbose shows:
| Error 2014-03-12 19:58:37,745 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - ArrayIndexOutOfBoundsException occurred when processing request: [GET] /imca2/imcaReferral/index
0. Stacktrace follows:
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.criterion.Order.toSqlString(Order.java:73)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.java:394)
[snip]
at grails.orm.PagedResultList.<init>(PagedResultList.java:55)
[snip]
at com.ubergen.ImcaReferral.list(ImcaReferral.groovy)
[snip]
at com.ubergen.ImcaReferralController.$tt__index(script1394654146228610896735.groovy:15)
[snip]
So the index page calls the domain's list() and this is a problem in some way but not enough of a way that its getting mentioned in the stacktrace.
Where should I look first for the problem?
Versions:
ubuntu 10.04
eclipse / SpringToolSuite 3.4.0
grails 2.3.6
groovy 2.1.9 (for both project and workspace)
Update 13/03/2014
I followed Joe's suggestions (below) and found that the problem is indeed in the ImcaReferral.list() method.
In the grails console simply running:
package com.ubergen
ImcaReferral.withTransaction { status ->
ImcaReferral.list()
}
Returns
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.criterion.Order.toSqlString(Order.java:73)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.ja a:394)
[snip]
at com.ubergen.ImcaReferral.list(ImcaReferral.groovy)
Looking at the domain's sort order information BINGO! its incorrectly defined, there are two competing definitions of how to sort the domain.
I Comment out the erroneous sort order information:
package com.ubergen
class ImcaReferral {
...
static hasMany = [challenges:Challenge]
static mapping = {
...
sort dateReceived:'asc'
// sort challenges:'challengeRoute' // *** ERROR ***
}
}
and (after restarting the console) the call to list works fine and returns an empty array.
Correcting the sort order of the child records:
package com.ubergen
class ImcaReferral {
...
static hasMany = [challenges:Challenge]
static mapping = {
...
sort dateReceived:'asc'
challenges sort: 'challengeRoute', order: 'asc' // *** CORRECT ***
}
}
Fixes the problem. The scaffolding now works.
Conclusions
Trust the full stacktrace even if its rather verbose. It shows the classes and methods to look at.
Learn to use the console.
grails -reloading console
Read your more code carefully!

You could try to generate the Static Scaffolding and see if you get a different result. You could also try running the list in a integration test to see what happens.

Related

Fitnesse cannot find class unless it has a wiki page

I'm running into some odd behavior when trying to setup an ActionFixture test using Fitnesse (with FitSharp as the test runner)
When creating an actionFixture I'll get an error that the class (Namespace.TestClassName in example below) cannot be found. If I create a wiki page for it the test will work.
| actionFixture |
| start | Namespace.TestClassName |
Is it required to have a page for each class? If so can I reference the same page for all tests (different location in hierarchy)?
Sorry for the naive question, sure I'm missing something simple here.
Simple error on my part;
Needed to enclose the class name as shown below
| actionFixture |
| start | !-Namespace.TestClassName-! |
...or simply don't write the name as a wikiword;
| actionFixture |
| start | namespace.testClassName |

using the server variable in ember-cli-mirage tests

I'm trying to use ember-cli-mirage in my tests but running into problems. I'm using ember and ember-data 2.1.0 so that may have something to do with this.
I'm able to use mirage in development just fine. I've defined factories, routes, scenarios, etc with no problem.
The problem is when i attempt to create models in tests. The test below errors out:
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'frontend/tests/helpers/start-app';
let application;
module('Acceptance | Customer', {
beforeEach() {
application = startApp();
},
afterEach() {
Ember.run(application, 'destroy');
}
});
test('viewing customers', function(assert) {
server.createList('customer', 2);
visit('/admin/customers');
andThen(() => assert.equal(find('#customers-table tbody tr').length, 2));
});
This results in:
not ok 1 PhantomJS 1.9 - Acceptance | Customer: viewing customers
---
actual: >
null
message: >
Died on test #1 at http://localhost:7357/assets/test-support.js:3124
at http://localhost:7357/assets/frontend.js:2434
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:6846: 'undefined' is not a function (evaluating 'newCollection[method].bind(newCollection)')
Log: |
...
Should I be bootstrapping mirage somewhere?
This is actually caused by Phantom 1.9 not having bind (you can see in the error message, undefined refers to bind).
If you view the other notes section of the Installation docs you'll see you can get around this by installing ember-cli-es5-shim (or upgrading to PhantomJS 2.0).

Producing a Webbapp War file - Error that parameter will be ignored

I’m trying to get a Project running on Tomcat7 that requires some Plugins and is written in Grails.
Creating a -war with the command grails prod war results in an Error that tells me a parameter of type [java.util.List] is not supported.
Where and how can i see which parameter are Supported and why List isn’t ?
the logfile with the errors looks like this:
| Loading Grails 2.4.1
| Configuring classpath
| Configuring classpath.
| Environment set to production
| Environment set to production.
| Environment set to production..
| Environment set to production...
| Environment set to production....
| Environment set to production.....
| Packaging Grails application
| Packaging Grails application.
| Packaging Grails application..
| Packaging Grails application...
| Packaging Grails application....
| Packaging Grails application.....
| Compiling 70 source files
| Warning The [listFullAccessResources] action in [VsGrantController] accepts a parameter of type [java.util.List]. Interface types and abstract class types are not supported as command objects. This parameter will be ignored.
List listFullAccessResources(VsUser loggedInUser, List resultsGoups) {
^
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] General error during class generation: java.lang.NoClassDefFoundError: Unable to load class org.jets3t.service.impl.rest.httpclient.RestS3Service due to missing dependency org/apache/http/client/methods/HttpHead
[groovyc]
[groovyc] java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class org.jets3t.service.impl.rest.httpclient.RestS3Service due to missing dependency org/apache/http/client/methods/HttpHead
[groovyc] at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1083)
The VsGrantController.groovy looks like this
import org.apache.commons.lang.StringUtils
class VsGrantController {
def vsAuthenticateService
def vsGrantService
def index = { redirect(action:list,params:params) }
// the delete, save and update actions only accept POST requests
static allowedMethods = [delete:'POST', save:'POST', update:'POST']
List listFullAccessResources(VsUser loggedInUser, List resultsGoups) {
// labels user has full access to
def cLabels = VsLabel.createCriteria()
def resultsLabelsFullAccess = cLabels.listDistinct {
grants {
and {
permission {
eq("name", 'Full')
}
or {
eq("accessor", loggedInUser)
if(resultsGoups) {
or {
for (g in resultsGoups) {
eq("accessor", g)
}
}
}
}
}
}
order("name")
}
I'm kind of new to the Grails/Groovy Tomcat Webbapp Topic
so i hope this question is not to bad
The warning "Interface types and abstract class types are not supported as command objects." complains because your controller action has a List resultsGoups parameter. This is not supported.
You can extract the parameters from the implicit 'params' map or by using a command object.
Something like this...
def listFullAccessResources(AccessResourcesCommand cmd) {
}
class AccessResourcesCommand {
Bar loggedInUser
List resultsGroups
}
Your actual error is
Unable to load class org.jets3t.service.impl.rest.httpclient.RestS3Service due to missing dependency org/apache/http/client/methods/HttpHead
You need to include httpclient.jar in the classpath
Change it to:
def List listFullAccessResources(VsUser loggedInUser, List resultsGoups)
and your warning will go away...

Can't access any bean from Quartz Job in Grails

I am using services in grails and getting and setting data from services in controllers and there is no problem. I know how to use it... But this problem I can't solve, please help me if you know what is going wrong.
There is a QuartzJob, I schedule from service from controller... Data is stored in PostgreSQL. Using last version of all plugins and 2.3.3 Grails. In code below I just want to print nickname, but I can't get service. Tried to get bean, def grailsApplication but with no success.
Grails plugin for Quartz is quartz:1.0-RC11
class TestJob implements Job{
def userService
void execute(org.quartz.JobExecutionContext t) {
try {
println userService.getUserProfile("farko").username
} catch (Exception ex){
println ex.printStackTrace()
}
}
}
I getting this error
Error | java.lang.NullPointerException: Cannot invoke method
getUserProfile() on null object Error | at
org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
Error | at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
Error | at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error | at
org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
Error | at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error | at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
Error | at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
Error | at test.TestJob$$EOTRiFAo.execute(TestJob.groovy:27) Error |
at test.TestJob$$DOTRiFAo.execute(Unknown Source) Error | at
test.TestJob.execute(TestJob.groovy) Error | at
org.quartz.core.JobRunShell.run(JobRunShell.java:207) Error | at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560)
null
You implement Job, but this is rare when using the plugin. Typically you just create a class in grails-app/jobs (either by hand or with the create-job script) with a name that ends in "Job", and the magic happens. Are you creating the classes in src/groovy? You need to use the plugin's conventions to get dependency injection to work.

Ambiguous method overloading for method grails.spring.BeanBuilder#registerBeans

I'm following Mike Kelly's brilliant tutorial videos but I have been stumped by the following problem. It happens when I add a new Domain Class. I've tried backing out changes and adding a DomainClass with a different name, restarting the IDE, etc. With only one Domain Class I have no error, if I add one the error appears.
I'm working with ggts 3.4.0, Grail 2.3.1, JDK 1.7.0_45.
| Error 2013-11-04 21:56:37,442 [Thread-8] ERROR plugins.AbstractGrailsPluginManager - Plugin [domainClass:2.3.1] could not reload changes to file [C:\Grails\ProjectTracker\grails-app\domain\projecttracker\EndUser.groovy]: Ambiguous method overloading for method grails.spring.BeanBuilder#registerBeans.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface org.codehaus.groovy.grails.commons.spring.RuntimeSpringConfiguration]
[interface org.springframework.beans.factory.support.BeanDefinitionRegistry]
Message: Ambiguous method overloading for method grails.spring.BeanBuilder#registerBeans.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface org.codehaus.groovy.grails.commons.spring.RuntimeSpringConfiguration]
[interface org.springframework.beans.factory.support.BeanDefinitionRegistry]
Line | Method
->> 2980 | chooseMostSpecificParams in groovy.lang.MetaClassImpl
This is a bug. I was able to reproduce the problem when I was investigating http://jira.grails.org/browse/GRAILS-10735 .
You can override the ambiguous method when passing null to its parameter
MyClass.metaClass.myAmbiguousMethod = {def param ->
if(param != null){
myAmbiguousMethod(param)
} else{
null
}
}
I can reproduce this in grails 3.2.4 by providing a render invalidVariablestatement. Bad argument to render can cause this from what I can tell

Resources