You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2016/07/01 17:58:59 UTC
shiro git commit: SHIRO-473 Fix NPE thrown from
DefaultAnnotationResolver.getAnnotation
Repository: shiro
Updated Branches:
refs/heads/master 08a860f5a -> 3ca513f1f
SHIRO-473 Fix NPE thrown from DefaultAnnotationResolver.getAnnotation
Project: http://git-wip-us.apache.org/repos/asf/shiro/repo
Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/3ca513f1
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/3ca513f1
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/3ca513f1
Branch: refs/heads/master
Commit: 3ca513f1f2f0472251b73c16c1507034a7028b24
Parents: 08a860f
Author: Brian Demers <bd...@apache.org>
Authored: Fri Jul 1 13:53:03 2016 -0400
Committer: Brian Demers <bd...@apache.org>
Committed: Fri Jul 1 13:53:03 2016 -0400
----------------------------------------------------------------------
.../org/apache/shiro/aop/DefaultAnnotationResolver.java | 7 ++++++-
.../java/org/apache/shiro/aop/AnnotationResolverTest.java | 10 ++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/shiro/blob/3ca513f1/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java b/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java
index d33eebe..d7fd4ae 100644
--- a/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java
+++ b/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java
@@ -59,6 +59,11 @@ public class DefaultAnnotationResolver implements AnnotationResolver {
}
Annotation annotation = m.getAnnotation(clazz);
- return annotation == null ? mi.getThis().getClass().getAnnotation(clazz) : annotation;
+ if (annotation == null ) {
+ Object miThis = mi.getThis();
+ //SHIRO-473 - miThis could be null for static methods, just return null
+ annotation = miThis != null ? miThis.getClass().getAnnotation(clazz) : null;
+ }
+ return annotation;
}
}
http://git-wip-us.apache.org/repos/asf/shiro/blob/3ca513f1/core/src/test/java/org/apache/shiro/aop/AnnotationResolverTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/shiro/aop/AnnotationResolverTest.java b/core/src/test/java/org/apache/shiro/aop/AnnotationResolverTest.java
index 545f35d..1b2916c 100644
--- a/core/src/test/java/org/apache/shiro/aop/AnnotationResolverTest.java
+++ b/core/src/test/java/org/apache/shiro/aop/AnnotationResolverTest.java
@@ -60,5 +60,15 @@ public class AnnotationResolverTest {
replay(methodInvocation);
assertNotNull(annotationResolver.getAnnotation(methodInvocation, RequiresUser.class));
}
+
+ @Test
+ public void testNullMethodInvocation() throws SecurityException, NoSuchMethodException {
+ MethodInvocation methodInvocation = createMock(MethodInvocation.class);
+ Method method = MyFixture.class.getDeclaredMethod("operateThis");
+ expect(methodInvocation.getMethod()).andReturn(method);
+ expect(methodInvocation.getThis()).andReturn(null);
+ replay(methodInvocation);
+ assertNull(annotationResolver.getAnnotation(methodInvocation, RequiresUser.class));
+ }
}