shiro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergiy Sokolenko (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (SHIRO-473) DefaultAnnotationResolver.getAnnotation throws NullPointerException
Date Tue, 26 Nov 2013 16:42:35 GMT

     [ https://issues.apache.org/jira/browse/SHIRO-473?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Sergiy Sokolenko updated SHIRO-473:
-----------------------------------

    Description: 
h3. Bug Description

The method org.apache.shiro.aop.DefaultAnnotationResolver.getAnnotation throws NullPointerException
when a given MethodInvocation argument represents static method:

h3. Technical Info

[http://shiro.apache.org/static/1.2.2/apidocs/src-html/org/apache/shiro/aop/DefaultAnnotationResolver.html#line.62]:
{code}
return annotation == null ? mi.getThis().getClass().getAnnotation(clazz) : annotation;
{code}

if annotation is null and mi represents static method invocation, then mi.getThis() will return
null causing the following chained call {{getClass()}} fail with NullPointerException.

I get this exception when I add Shiro annotation(s) to Play Framework's controller action,
like this:

{code}
public class Application extends Controller {
    @RequiresAuthentication
    public static Result index() {
        return ok("Hello Shiro!");
    }
}
{code}

h3. Possible Solution

Return null if mi.getThis() is null in DefaultAnnotationResolver.getAnnotation:
{code}
if (annotation == null) {
    Object o = mi.getThis();
    if (o != null) {
        annotation = o.getClass().getAnnotation(clazz);
    }
}
return annotation;
{code}

  was:
h3. Bug Description

The method org.apache.shiro.aop.DefaultAnnotationResolver.getAnnotation throws NullPointerException
when a given MethodInvocation argument represents static method:

h3. Technical Info

[org.apache.shiro.aop.DefaultAnnotationResolver.java: Line 62|http://shiro.apache.org/static/1.2.2/apidocs/src-html/org/apache/shiro/aop/DefaultAnnotationResolver.html#line.62]:
{code}
return annotation == null ? mi.getThis().getClass().getAnnotation(clazz) : annotation;
{code}

if annotation is null and mi represents static method invocation, then mi.getThis() will return
null causing the following chained call {{getClass()}} fail with NullPointerException.

I get this exception when I add Shiro annotation(s) to Play Framework's controller action,
like this:

{code}
public class Application extends Controller {
    @RequiresAuthentication
    public static Result index() {
        return ok("Hello Shiro!");
    }
}
{code}

h3. Possible Solution

Return null if mi.getThis() is null in DefaultAnnotationResolver.getAnnotation:
{code}
if (annotation == null) {
    Object o = mi.getThis();
    if (o != null) {
        annotation = o.getClass().getAnnotation(clazz);
    }
}
return annotation;
{code}


> DefaultAnnotationResolver.getAnnotation throws NullPointerException
> -------------------------------------------------------------------
>
>                 Key: SHIRO-473
>                 URL: https://issues.apache.org/jira/browse/SHIRO-473
>             Project: Shiro
>          Issue Type: Bug
>          Components: Integration: JEE
>    Affects Versions: 1.2.2
>         Environment: Cross platform / Play Framework 2.2
>            Reporter: Sergiy Sokolenko
>              Labels: AOP, AnnotationResolver, NullPointerException
>
> h3. Bug Description
> The method org.apache.shiro.aop.DefaultAnnotationResolver.getAnnotation throws NullPointerException
when a given MethodInvocation argument represents static method:
> h3. Technical Info
> [http://shiro.apache.org/static/1.2.2/apidocs/src-html/org/apache/shiro/aop/DefaultAnnotationResolver.html#line.62]:
> {code}
> return annotation == null ? mi.getThis().getClass().getAnnotation(clazz) : annotation;
> {code}
> if annotation is null and mi represents static method invocation, then mi.getThis() will
return null causing the following chained call {{getClass()}} fail with NullPointerException.
> I get this exception when I add Shiro annotation(s) to Play Framework's controller action,
like this:
> {code}
> public class Application extends Controller {
>     @RequiresAuthentication
>     public static Result index() {
>         return ok("Hello Shiro!");
>     }
> }
> {code}
> h3. Possible Solution
> Return null if mi.getThis() is null in DefaultAnnotationResolver.getAnnotation:
> {code}
> if (annotation == null) {
>     Object o = mi.getThis();
>     if (o != null) {
>         annotation = o.getClass().getAnnotation(clazz);
>     }
> }
> return annotation;
> {code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message