Uploaded image for project: 'S2Container'
  1. S2Container
  2. CONTAINER-357

[S2Container] AbstractInterceptor の冗長なコードを削除しました.

XMLWordPrintable

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major Major
    • 2.4.35
    • Affects Version/s: 2.4.34
    • Component/s: S2Container
    • None

      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;
           }
       
           /**
      

            Assignee:
            koichik koichik
            Reporter:
            r_ikeda r_ikeda
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: