Forums: Open Discussion (Thread #19336)

【バッチFW】NullColumnFormatterについて (2008-07-17 16:38 by kevin_vain #37651)

バッチFWを使用させていただいております。

ファイル書き込み際に、String型のカラムがNULLの場合、NullPointerExceptionが発生していますが、ColumnFormatterの原因でしょうか?

ソースコードをみますと;
46行目;return method.invoke(t).toString();

一時対策として、以下のようなColumnFormatterを実装していますが、よろしいでしょうか?

Object o = method.invoke(t);
if (o != null) {
return method.invoke(t).toString();
} else {
return "";
}

以上
よろしくお願いいたします。

Reply to #37651×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 【バッチFW】NullColumnFormatterについて (2008-07-23 18:37 by kuramotoki #37787)

ファイル行オブジェクトでのString項目がNULLの場合、
バッチFWがデフォルトで設定しているNullColumnFormatter, NullColumnParserを使用すると、
NullPointerExceptionが発生します。
これらのクラスは項目がNULLかどうかは考慮せずに処理を実行します。
NULL値を「""(空文字)」にするか例外とするかは業務仕様によると考えているからです。

項目の値がNULLの場合の対応方法は、提示されている方法で問題ないですが、
下記のようにしたほうがより良いと思います。
===
  Object o = method.invoke(t);
  if (o != null) {
    //return method.invoke(t).toString(); //←method.invoke(t)を再度実行せず、
return o.toString();   // ← すでに取得しているObjectでtoString()する
} else {
return "";
}
===
以上です。
Reply to #37651

Reply to #37787×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: 【バッチFW】NullColumnFormatterについて (2008-07-24 14:05 by kevin_vain #37798)

了解しました。
ありがとうございました。
Reply to #37787

Reply to #37798×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login