0

以下に示すように、「messageString」がnullでない場合、「messageString」を引数として渡して例外を呼び出しています

if (messageString !=null) {
  throw new org.jaffa.exceptions.ApplicationExceptions(
    new com.mirotechnologies.task.core.domain.exceptions.TaskException(
        com.mirotechnologies.task.core.domain.exceptions.TaskException.MANDATORY_FIELD, 
        messageString
    )
  );     
}

(AOPスニペット内にあるため、クラスのフルパスを記述する必要があります)

そうでない場合messageStringは正常に機能nullし、メッセージを適切に表示します。

しかし、それがの場合null、実際には例外で実行時エラーをスローしています。

undefined argument 'messageString' at : throw new org.jaffa.exceptions.ApplicationExceptions(new com.mirotechnologies.task.core.domain.exceptions.TaskException(com.mirotechnologies.task.core.domain.exceptions.TaskException.MANDATORY_FIELD, messageString)); 

AOP 内にあるため、これをデバッグできません。また、null の場合にループ内に入る理由もわかりません - TaskException コンストラクターへのあいまいな null パラメーターのコンパイラの問題である可能性がありますか?

TaskException 内のコンストラクター宣言は次のとおりです。

public TaskException(String propertyName, Object parameter0) {
        this(propertyName, new Object[] {parameter0});
}

public TaskException(String propertyName, Object[] parameters) {
        super(propertyName, parameters);
}

messageStringJava スニペットでを渡すときにキャストを追加する必要がありますか?

更新: 例外をスローするときにキャスト (Object )messageString を追加しましたが、「void」値を java.lang.Object にキャストできないというエラーがスローされます。メッセージ文字列が null ですか?

最初に、最初の行は java.lang.String messageString = null; として宣言されます。

4

1 に答える 1

1

あなたはそれがコンストラクターnullの文脈におけるの曖昧さであると推測するのは正しいです。TaskException's

次の電話を試してみてください。

new TaskException(TaskException.MANDATORY_FIELD, new Object[] {messageString})
于 2012-10-04T00:15:54.737 に答える