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