S2 でヌルポ

OGNL で遊んでいて,S2 (2.1.2) にちょっとした問題を見つけてしまいました.
<component> 要素に OGNL 式を記述した場合ですが,評価結果が null になった場合にコンテナからヌルポが飛んできます.

    <component name="foo">null</compoent>

で確認できます.


org.seasar.framework.container.assembler.ExpressionConstructorAssembler の31行目〜

        component = OgnlUtil.getValue(exp, container);
        if (componentClass != null) {
            if (!componentClass.isInstance(component)) {
                throw new ClassUnmatchRuntimeException(componentClass,
                    component.getClass());
            }
        }

ClassUnmatchRuntimeException のコンストラクタ中で呼び出している component.getClass()componentnull なためです.
nullコンポーネントをどうするかはコンテナの仕様として微妙な感じですね...
別途例外でしょうか?


それから S2TestCase ですが,やはり <component> 要素に OGNL 式を記述した場合で class 属性がない場合にヌルポになります.

    <component name="bar">"hoge"</component>

で確認することが出来ます.
org.seasar.extension.unit.S2TestCase の 1030 行目付近

            if (getContainer().hasComponentDef(name)
                    && field.getType().isAssignableFrom(
                            getComponentDef(name).getComponentClass())) {
                component = getComponent(name);

Class#isAssignableFrom(Class) の引数が null になるためです.
もちろん

    <component name="bar" class="java.lang.String">"hoge"</component>

にするとちゃんと動きますが,これだと Kijimuna が警告を出します (これは先日のからさわぎで既知の問題として話があったような?).


以上,ご報告まで.
っていうか,こういうのは ML か?(^^;