• Type: Improvement
    • Resolution: Fixed
    • Priority: 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;
           }
       
           /**
      

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

          koichik added a comment -

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

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

              Created:
              Updated:
              Resolved: