Melody Plugin

GrailsMelody - IllegalARgumentException by metaMethod.doMethodInvoke(delegate, args) in GrailsMelodyGrailsPlugin.groovy

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:

Description

I noticed this in my integration tests today.

My setup is as follows:

class TicketController {
    def read {
        ticketService.read(params.id as int)
    }
}

Passing in that value in the argument to the method will cause a java.lang.IllegalArgumentException: argument type mismatch

Changing that to :

class TicketController {
    def read {
        def id = params.id as int
        ticketService.read(id)
    }
}

Exception looks something like this :

java.lang.IllegalArgumentException: argument type mismatch
at GrailsMelodyGrailsPlugin$_closure5_closure18_closure19.doCall(GrailsMelodyGrailsPlugin.groovy:156)
at ....helpdesk.TicketController$_closure12.doCall(TicketController.groovy:192)
at ....helpdesk.TicketController$_closure12.doCall(TicketController.groovy)
at ....helpdesk.TicketControllerTests.testGetRemediatedAffectedAssets(TicketControllerTests.groovy:354)

Activity

Hide
Rafal Niedzialkowski added a comment -

I meant to state that changing the code to the 2nd example resolves the exception. Did not mean to imply that also does not work.

Show
Rafal Niedzialkowski added a comment - I meant to state that changing the code to the 2nd example resolves the exception. Did not mean to imply that also does not work.
Hide
Rafal Niedzialkowski added a comment -

I think I've narrowed this down further, the GrailsMelodyGrailsPlugin.doWithDynamicMethods closure has an issue locating the correct method definition when you have dynamic arguments generated.

Example, given this method definition in a service class:

def sendNotification(subject,body,options = 0) {
....
}

Inside of GrailsMelodyGrailsPlugin line 48, the delete.metaClass.getMetaMethod(name,args) will actually fail to locate the correct method. I'm assuming its because if you provide a default optional value for one of the arguments you actually end up w/ 2 methods w/ different signatures, one w/ 2 arguments, and one w/ 3. The lookup on getMetaMethod(name,args) doesn't appear to match probably because the auto-generated method will be generated w/ Object as the argument types for all the arguments.

This causes the plugin to try to match by name only, which is going to go in sequential order and find the first method (the 2 argument one), vs the 3 argument one, and result in an ArrayIndexOutOfBoundsException when the plugin attempts to invoke the method w/ 3 arguments.

Show
Rafal Niedzialkowski added a comment - I think I've narrowed this down further, the GrailsMelodyGrailsPlugin.doWithDynamicMethods closure has an issue locating the correct method definition when you have dynamic arguments generated. Example, given this method definition in a service class:
def sendNotification(subject,body,options = 0) {
....
}
Inside of GrailsMelodyGrailsPlugin line 48, the delete.metaClass.getMetaMethod(name,args) will actually fail to locate the correct method. I'm assuming its because if you provide a default optional value for one of the arguments you actually end up w/ 2 methods w/ different signatures, one w/ 2 arguments, and one w/ 3. The lookup on getMetaMethod(name,args) doesn't appear to match probably because the auto-generated method will be generated w/ Object as the argument types for all the arguments. This causes the plugin to try to match by name only, which is going to go in sequential order and find the first method (the 2 argument one), vs the 3 argument one, and result in an ArrayIndexOutOfBoundsException when the plugin attempts to invoke the method w/ 3 arguments.
Hide
Charles Erwin added a comment -

I'm having this same issue with a controller method with optional parameters in Grails 1.3.6

Show
Charles Erwin added a comment - I'm having this same issue with a controller method with optional parameters in Grails 1.3.6
Hide
Alexander Franz added a comment -

I have a similar issue: I get an ArrayIndexOutOfBoundsException when calling a service method from a controller.

Show
Alexander Franz added a comment - I have a similar issue: I get an ArrayIndexOutOfBoundsException when calling a service method from a controller.
Hide
Emeric Vernat added a comment -

I suggest to try a newer version, because there was a fix in v1.1 of the plugin, based on a patch by Jean Barmash.
Let us know if it fixes your issue. Thanks

Show
Emeric Vernat added a comment - I suggest to try a newer version, because there was a fix in v1.1 of the plugin, based on a patch by Jean Barmash. Let us know if it fixes your issue. Thanks
Hide
Eric Brayeur added a comment -

Hi,
I'm having the problem with both versions 1.9 and 1.10 :

Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
at GrailsMelodyGrailsPlugin$_closure5_closure18_closure19.doCall(GrailsMelodyGrailsPlugin.groovy:170)

Show
Eric Brayeur added a comment - Hi, I'm having the problem with both versions 1.9 and 1.10 : Caused by: java.lang.ArrayIndexOutOfBoundsException: 2 at GrailsMelodyGrailsPlugin$_closure5_closure18_closure19.doCall(GrailsMelodyGrailsPlugin.groovy:170)
Hide
Emeric Vernat added a comment -

Ok. An issue is also created in javamelody to warn about the problem:
http://code.google.com/p/javamelody/issues/detail?id=165

And what should be the patch in GrailsMelodyGrailsPlugin.groovy to reduce or fix the problem?
https://svn.codehaus.org/grails-plugins/grails-grails-melody/trunk/GrailsMelodyGrailsPlugin.groovy

Show
Emeric Vernat added a comment - Ok. An issue is also created in javamelody to warn about the problem: http://code.google.com/p/javamelody/issues/detail?id=165 And what should be the patch in GrailsMelodyGrailsPlugin.groovy to reduce or fix the problem? https://svn.codehaus.org/grails-plugins/grails-grails-melody/trunk/GrailsMelodyGrailsPlugin.groovy

People

Vote (3)
Watch (3)

Dates

  • Created:
    Updated: