[CONTAINER-357] [S2Container] AbstractInterceptor の冗長なコードを削除しました. Created: 2009-04-12  Updated: 2009-04-13  Resolved: 2009-04-13

Status: Resolved
Project: S2Container
Component/s: S2Container
Affects Version/s: 2.4.34
Fix Version/s: 2.4.35

Type: Improvement Priority: Major
Reporter: r_ikeda Assignee: koichik
Resolution: Fixed Votes: 0
Labels: None


 Description   

org.seasar.framework.aop.interceptors.AbstractInterceptor の getTargetClass メソッドについてです。
...

protected Class getTargetClass(MethodInvocation invocation) {
    if (invocation instanceof S2MethodInvocation) {
        return ((S2MethodInvocation) invocation).getTargetClass();
    }
    Class thisClass = invocation.getThis().getClass();
    Class superClass = thisClass.getSuperclass();
    if (superClass == Object.class) {
        return thisClass.getInterfaces()[0];
    }
    return superClass;
}

8 行目で thisClass.getInterfaces()[0]; としていますが、インターフェースを実装していないクラスの場合、
長さ 0 の配列が返されるため、それをチェックする必要があると思います。
インターフェースを実装していなかった場合は、thisClass を返すようにするのがいいと思うのですが、どうでしょうか。

Index: s2-framework/src/main/java/org/seasar/framework/aop/interceptors/AbstractInterceptor.java
===================================================================
--- s2-framework/src/main/java/org/seasar/framework/aop/interceptors/AbstractInterceptor.java	(revision 4270)
+++ s2-framework/src/main/java/org/seasar/framework/aop/interceptors/AbstractInterceptor.java	(working copy)
@@ -63,10 +63,14 @@
         }
         Class thisClass = invocation.getThis().getClass();
         Class superClass = thisClass.getSuperclass();
-        if (superClass == Object.class) {
-            return thisClass.getInterfaces()[0];
+        if (superClass != Object.class) {
+            return superClass;
         }
-        return superClass;
+        Class[] interfaces = thisClass.getInterfaces();
+        if (interfaces.length > 0) {
+            return interfaces[0];
+        }
+        return thisClass;
     }
 
     /**


 Comments   
Comment by koichik [ 2009-04-13 ]

対応しました.
http://svn.seasar.org/browse/?view=rev&root=s2container&revision=4271

Generated at Wed Apr 24 18:45:49 JST 2024 using Jira 9.15.0#9150000-sha1:9ead8528714127d8cfabf2446010d7e62c0a195c.