Title: Is it a bug of grails?
Tags: grails
Question: When I typed these code, it works perfectly.
def users = User.getAll(params.userChecked)*.id
println 'user : ' + users
But when I did like this, it shows error
def users = User.getAll(params.userChecked)*.id
println 'user : ' + users
def x = [1, 2]
x.each(){
def roles = Role.withCriteria{
users {
eq 'id', new Long(80)
}
println roles
But when I removed above code, the below was normally worked.
def x = [1, 2]
x.each(){
def roles = Role.withCriteria{
users {
eq 'id', new Long(80)
}
println roles
I didn't understand what's wrong ? Here's the error
No signature of method: java.util.ArrayList.call()...

Here is the accepted answer: You just replace
def users = User.getAll(params.userChecked)*.id
def usersList = User.getAll(params.userChecked)*.id
You have two different list one in hasMany, that name users and another defining in controller that creating confusion just change name . All code will work fine.
def users = User.getAll(params.userChecked)*.id
println 'user : ' + users
def x = [1, 2]
x.each(){
def roles = Role.withCriteria{
users {
eq 'id', new Long(80)
}
}
println roles
Comment for this answer: The root of the problem is that when there is a variable named `users` in scope at the point when you call `withCriteria`, the `users { ... }` block inside the criteria closure is treated by Groovy as an invocation of the `call` method of the in-scope `users` object, rather than as an invocation of the `users` method on the criteria builder (the closure delegate).

Here is another answer: As explained in the other answer, the problem is the name clash between the users variable in the outer scope and the users {...} call inside the criteria closure.  The simplest way to fix this is to rename the variable, but if that is not an option then an alternative fix is to use delegate. inside the closure:
def roles = Role.withCriteria{
delegate.users {
eq 'id', new Long(80)
This removes the ambiguity and forces Groovy to send the call to the closure delegate (the criteria builder) instead of the variable in the containing scope.  You can use the same trick anywhere else where you have a name clash with a builder, I've had to use it in the past when creating XML with a MarkupBuilder.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:03/24/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<grails>', 'Title': 'Is it a bug of grails?', 'ViewCount': 63, 'id': 29230199, 'user_AboutMe': '', 'user_AccountId': 5144135.0, 'user_DisplayName': 'Hikaru Shindo', 'user_Reputation': 2362.0, 'user_Views': 301.0, 'user_id': 4120583.0}}