Infinite loop in Filters when accessing value() of annotation

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Infinite loop in Filters when accessing value() of annotation

Matthias Wenz
Hi there,

I'm trying to write an annotation for Grails actions which allows me to specify required parameters for an action.
I want to evaluate that using a filter which checks whether the called controller-action has the appropriate annotation, the extracting its contents and check whether all the required fields are set in the params-map.
But I don't get this far. I can log the annotation, but every time I try to access its value()-method the whole JVM hangs up on itself in one thread.

Here's what I built:

RequiredParameters.java , modeled after grails.plugins.springsecurity.Secured:
---
package de.bowstreet.grails.plugins;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface RequiredParameters {
    String[] value();
}
---
And my filter:

RequiredParametersFilters.groovy:
---
package app

[…]

class RequiredParametersFilters {
   
    def filters = {
        all(controller:'*', action:'*') {
            before = {
               
                def controller = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)
               
                log.debug controller
               
                RequiredParameters requiredParameters = null
               
                if (controller) {
                    Class controllerClass = controller.clazz
                   
                    log.info controllerClass
                   
                    def method = controllerClass.getMethod(actionName, [] as Class[])
                    if (method.isAnnotationPresent(RequiredParameters)) {
                        log.info method.getAnnotation(RequiredParameters).value()
                    }
                }
               
                return true
            }
        }
    }
}
---

I add the annotation to a simple controller like this:
---
class RootController {
   
    @RequiredParameters(['id'])
    def index() {
        log.info "Test"
    }
}
---

When I try to access the controller, I get all the log statements except the one from "log.info method.getAnnotation(RequiredParameters).value()" - at this point the JVM is stuck in what looks like an infinite loop except I can't identify it in the debugger to see where it originates from.

I tried the same thing with the @Secured annotation from the Spring Security plugin - this works fine.

What am I doing wrong?

Thanks,
Mat
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop in Filters when accessing value() of annotation

ivan_d
I had the same problem with custom annotations I added to an app (although, in my app the annotations were read from a service instead of a filter). I couldn't figure out what the reason for the blocking was (the block seemed to occur only when the value property of the annotation was accessed), so I tried moving the annotation definition into the same package as the Secured annotation in the spring-security-core plugin (since that annotation appeared to work just fine). Lo and behold that fixed it (admittedly, it's an extremely clumsy workaround). Now I'm waiting on the final 2.2 release to find out if moving the annotation back into my app's source tree will work too.
Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop in Filters when accessing value() of annotation

Owen Rubel
In reply to this post by Matthias Wenz
I am having same issue. I appear to have an infinite loop when trying to access values of annotation in filter. Is this a bug or is there a special way to do it?


On Wed, Dec 19, 2012 at 7:17 AM, Matthias Wenz <[hidden email]> wrote:
Hi there,

I'm trying to write an annotation for Grails actions which allows me to specify required parameters for an action.
I want to evaluate that using a filter which checks whether the called controller-action has the appropriate annotation, the extracting its contents and check whether all the required fields are set in the params-map.
But I don't get this far. I can log the annotation, but every time I try to access its value()-method the whole JVM hangs up on itself in one thread.

Here's what I built:

RequiredParameters.java , modeled after grails.plugins.springsecurity.Secured:
---
package de.bowstreet.grails.plugins;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface RequiredParameters {
    String[] value();
}
---
And my filter:

RequiredParametersFilters.groovy:
---
package app

[…]

class RequiredParametersFilters {

    def filters = {
        all(controller:'*', action:'*') {
            before = {

                def controller = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)

                log.debug controller

                RequiredParameters requiredParameters = null

                if (controller) {
                    Class controllerClass = controller.clazz

                    log.info controllerClass

                    def method = controllerClass.getMethod(actionName, [] as Class[])
                    if (method.isAnnotationPresent(RequiredParameters)) {
                        log.info method.getAnnotation(RequiredParameters).value()
                    }
                }

                return true
            }
        }
    }
}
---

I add the annotation to a simple controller like this:
---
class RootController {

    @RequiredParameters(['id'])
    def index() {
        log.info "Test"
    }
}
---

When I try to access the controller, I get all the log statements except the one from "log.info method.getAnnotation(RequiredParameters).value()" - at this point the JVM is stuck in what looks like an infinite loop except I can't identify it in the debugger to see where it originates from.

I tried the same thing with the @Secured annotation from the Spring Security plugin - this works fine.

What am I doing wrong?

Thanks,
Mat
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop in Filters when accessing value() of annotation

Owen Rubel

Hey all,

for those seeing this bug, test in 2.0.4. I just had someone help me with this issue and I was in 2.1.2 but they were able to get it to work fine in 2.0.4. I am not sure when this this BUG got introduced but I filed a JIRA ticket (http://jira.grails.org/browse/GRAILS-9706). Please feel free to add your comments and test cases if you are seeing a similar case.


On Sat, Dec 22, 2012 at 8:18 PM, Owen Rubel <[hidden email]> wrote:
I am having same issue. I appear to have an infinite loop when trying to access values of annotation in filter. Is this a bug or is there a special way to do it?


On Wed, Dec 19, 2012 at 7:17 AM, Matthias Wenz <[hidden email]> wrote:
Hi there,

I'm trying to write an annotation for Grails actions which allows me to specify required parameters for an action.
I want to evaluate that using a filter which checks whether the called controller-action has the appropriate annotation, the extracting its contents and check whether all the required fields are set in the params-map.
But I don't get this far. I can log the annotation, but every time I try to access its value()-method the whole JVM hangs up on itself in one thread.

Here's what I built:

RequiredParameters.java , modeled after grails.plugins.springsecurity.Secured:
---
package de.bowstreet.grails.plugins;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface RequiredParameters {
    String[] value();
}
---
And my filter:

RequiredParametersFilters.groovy:
---
package app

[…]

class RequiredParametersFilters {

    def filters = {
        all(controller:'*', action:'*') {
            before = {

                def controller = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)

                log.debug controller

                RequiredParameters requiredParameters = null

                if (controller) {
                    Class controllerClass = controller.clazz

                    log.info controllerClass

                    def method = controllerClass.getMethod(actionName, [] as Class[])
                    if (method.isAnnotationPresent(RequiredParameters)) {
                        log.info method.getAnnotation(RequiredParameters).value()
                    }
                }

                return true
            }
        }
    }
}
---

I add the annotation to a simple controller like this:
---
class RootController {

    @RequiredParameters(['id'])
    def index() {
        log.info "Test"
    }
}
---

When I try to access the controller, I get all the log statements except the one from "log.info method.getAnnotation(RequiredParameters).value()" - at this point the JVM is stuck in what looks like an infinite loop except I can't identify it in the debugger to see where it originates from.

I tried the same thing with the @Secured annotation from the Spring Security plugin - this works fine.

What am I doing wrong?

Thanks,
Mat
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop in Filters when accessing value() of annotation

Matthias Wenz
Thanks for digging into this, Owen.

What I found remarkable about the way the S2-Plugin does use the annotations is, that they only call "value()" on annotations in Java code - not in Groovy.
So I wrote not only my annotation in Java, but also a class that extracts the value from the given annotation. This works fine. So I guess it might also be a bug in Groovy.

My plugin now kind of works - so I published it here: https://github.com/ranterscheinung/grails-required-parameters

Feel free to have a look at it and tell me what you think.

Thanks,
Mat



Am 23.12.2012 um 16:52 schrieb Owen Rubel <[hidden email]>:


Hey all,

for those seeing this bug, test in 2.0.4. I just had someone help me with this issue and I was in 2.1.2 but they were able to get it to work fine in 2.0.4. I am not sure when this this BUG got introduced but I filed a JIRA ticket (http://jira.grails.org/browse/GRAILS-9706). Please feel free to add your comments and test cases if you are seeing a similar case.


On Sat, Dec 22, 2012 at 8:18 PM, Owen Rubel <[hidden email]> wrote:
I am having same issue. I appear to have an infinite loop when trying to access values of annotation in filter. Is this a bug or is there a special way to do it?


On Wed, Dec 19, 2012 at 7:17 AM, Matthias Wenz <[hidden email]> wrote:
Hi there,

I'm trying to write an annotation for Grails actions which allows me to specify required parameters for an action.
I want to evaluate that using a filter which checks whether the called controller-action has the appropriate annotation, the extracting its contents and check whether all the required fields are set in the params-map.
But I don't get this far. I can log the annotation, but every time I try to access its value()-method the whole JVM hangs up on itself in one thread.

Here's what I built:

RequiredParameters.java , modeled after grails.plugins.springsecurity.Secured:
---
package de.bowstreet.grails.plugins;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface RequiredParameters {
    String[] value();
}
---
And my filter:

RequiredParametersFilters.groovy:
---
package app

[…]

class RequiredParametersFilters {

    def filters = {
        all(controller:'*', action:'*') {
            before = {

                def controller = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)

                log.debug controller

                RequiredParameters requiredParameters = null

                if (controller) {
                    Class controllerClass = controller.clazz

                    log.info controllerClass

                    def method = controllerClass.getMethod(actionName, [] as Class[])
                    if (method.isAnnotationPresent(RequiredParameters)) {
                        log.info method.getAnnotation(RequiredParameters).value()
                    }
                }

                return true
            }
        }
    }
}
---

I add the annotation to a simple controller like this:
---
class RootController {

    @RequiredParameters(['id'])
    def index() {
        log.info "Test"
    }
}
---

When I try to access the controller, I get all the log statements except the one from "log.info method.getAnnotation(RequiredParameters).value()" - at this point the JVM is stuck in what looks like an infinite loop except I can't identify it in the debugger to see where it originates from.

I tried the same thing with the @Secured annotation from the Spring Security plugin - this works fine.

What am I doing wrong?

Thanks,
Mat
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





Reply | Threaded
Open this post in threaded view
|

Re: Infinite loop in Filters when accessing value() of annotation

Owen Rubel
Well this should be able to be called from within grails filters and such without having to call external java libs so this is a Grails bug. But thanks for the work around. I could probably use this for the time being for testing but would prefer a more long term fix for annotations in general.

Owen Rubel


On Thu, Dec 27, 2012 at 3:17 AM, Matthias Wenz <[hidden email]> wrote:
Thanks for digging into this, Owen.

What I found remarkable about the way the S2-Plugin does use the annotations is, that they only call "value()" on annotations in Java code - not in Groovy.
So I wrote not only my annotation in Java, but also a class that extracts the value from the given annotation. This works fine. So I guess it might also be a bug in Groovy.

My plugin now kind of works - so I published it here: https://github.com/ranterscheinung/grails-required-parameters

Feel free to have a look at it and tell me what you think.

Thanks,
Mat



Am 23.12.2012 um 16:52 schrieb Owen Rubel <[hidden email]>:


Hey all,

for those seeing this bug, test in 2.0.4. I just had someone help me with this issue and I was in 2.1.2 but they were able to get it to work fine in 2.0.4. I am not sure when this this BUG got introduced but I filed a JIRA ticket (http://jira.grails.org/browse/GRAILS-9706). Please feel free to add your comments and test cases if you are seeing a similar case.


On Sat, Dec 22, 2012 at 8:18 PM, Owen Rubel <[hidden email]> wrote:
I am having same issue. I appear to have an infinite loop when trying to access values of annotation in filter. Is this a bug or is there a special way to do it?


On Wed, Dec 19, 2012 at 7:17 AM, Matthias Wenz <[hidden email]> wrote:
Hi there,

I'm trying to write an annotation for Grails actions which allows me to specify required parameters for an action.
I want to evaluate that using a filter which checks whether the called controller-action has the appropriate annotation, the extracting its contents and check whether all the required fields are set in the params-map.
But I don't get this far. I can log the annotation, but every time I try to access its value()-method the whole JVM hangs up on itself in one thread.

Here's what I built:

RequiredParameters.java , modeled after grails.plugins.springsecurity.Secured:
---
package de.bowstreet.grails.plugins;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface RequiredParameters {
    String[] value();
}
---
And my filter:

RequiredParametersFilters.groovy:
---
package app

[…]

class RequiredParametersFilters {

    def filters = {
        all(controller:'*', action:'*') {
            before = {

                def controller = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)

                log.debug controller

                RequiredParameters requiredParameters = null

                if (controller) {
                    Class controllerClass = controller.clazz

                    log.info controllerClass

                    def method = controllerClass.getMethod(actionName, [] as Class[])
                    if (method.isAnnotationPresent(RequiredParameters)) {
                        log.info method.getAnnotation(RequiredParameters).value()
                    }
                }

                return true
            }
        }
    }
}
---

I add the annotation to a simple controller like this:
---
class RootController {

    @RequiredParameters(['id'])
    def index() {
        log.info "Test"
    }
}
---

When I try to access the controller, I get all the log statements except the one from "log.info method.getAnnotation(RequiredParameters).value()" - at this point the JVM is stuck in what looks like an infinite loop except I can't identify it in the debugger to see where it originates from.

I tried the same thing with the @Secured annotation from the Spring Security plugin - this works fine.

What am I doing wrong?

Thanks,
Mat
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email