shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdem...@apache.org
Subject shiro git commit: SHIRO-473 Fix NPE thrown from DefaultAnnotationResolver.getAnnotation
Date Fri, 01 Jul 2016 17:59:22 GMT
Repository: shiro
Updated Branches:
  refs/heads/1.3.x 5babc335f -> 8aec95ea6


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/8aec95ea
Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/8aec95ea
Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/8aec95ea

Branch: refs/heads/1.3.x
Commit: 8aec95ea6fd9a905587e2c5954cae59cfb2ccaa7
Parents: 5babc33
Author: Brian Demers <bdemers@apache.org>
Authored: Fri Jul 1 13:53:03 2016 -0400
Committer: Brian Demers <bdemers@apache.org>
Committed: Fri Jul 1 13:53:44 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/8aec95ea/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/8aec95ea/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));
+    }
 }
 


Mime
View raw message