Skip to content

Commit 700479d

Browse files
committed
add applicationfailureexception class and let data converter to fallback on this exception instead
Signed-off-by: Shijie Sheng <liouvetren@gmail.com>
1 parent 0e53403 commit 700479d

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
7+
* except in compliance with the License. A copy of the License is located at
8+
*
9+
* <p>http://aws.amazon.com/apache2.0
10+
*
11+
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
package com.uber.cadence.client;
16+
17+
import com.uber.cadence.CadenceError;
18+
import java.util.Objects;
19+
20+
public final class ApplicationFailureException extends CadenceError {
21+
22+
public ApplicationFailureException(String message) {
23+
super(message);
24+
}
25+
26+
@Override
27+
public boolean equals(Object obj) {
28+
if (this == obj) {
29+
return true;
30+
}
31+
if (obj == null || getClass() != obj.getClass()) {
32+
return false;
33+
}
34+
ApplicationFailureException that = (ApplicationFailureException) obj;
35+
return Objects.equals(getMessage(), that.getMessage())
36+
&& Objects.equals(getCause(), that.getCause());
37+
}
38+
39+
@Override
40+
public int hashCode() {
41+
return Objects.hash(getMessage(), getCause());
42+
}
43+
}

src/main/java/com/uber/cadence/converter/CustomThrowableTypeAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.gson.reflect.TypeToken;
2323
import com.google.gson.stream.JsonReader;
2424
import com.google.gson.stream.JsonWriter;
25+
import com.uber.cadence.client.ApplicationFailureException;
2526
import java.io.IOException;
2627
import java.io.PrintWriter;
2728
import java.io.StringWriter;
@@ -137,7 +138,7 @@ public T read(JsonReader jsonReader) throws IOException {
137138
try {
138139
classType = Class.forName(className);
139140
} catch (ClassNotFoundException e) {
140-
return null;
141+
return (T) new ApplicationFailureException("Class not found: " + className);
141142
}
142143
if (!Throwable.class.isAssignableFrom(classType)) {
143144
throw new IOException("Expected type that extends Throwable: " + className);

src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.uber.cadence.WorkflowExecutionStartedEventAttributes;
2828
import com.uber.cadence.WorkflowType;
2929
import com.uber.cadence.activity.Activity;
30+
import com.uber.cadence.client.ApplicationFailureException;
3031
import java.io.File;
3132
import java.io.FileInputStream;
3233
import java.io.IOException;
@@ -285,6 +286,9 @@ public void testExceptionNotFound() {
285286
convertedString.getBytes(StandardCharsets.UTF_8),
286287
RuntimeException.class,
287288
RuntimeException.class);
288-
assertNull(fromConverted);
289+
assertEquals(ApplicationFailureException.class, fromConverted.getClass());
290+
assertEquals(
291+
"Class not found: com.uber.cadence.converter.ExceptionNotFound",
292+
fromConverted.getMessage());
289293
}
290294
}

0 commit comments

Comments
 (0)