Skip to content

Commit 961c032

Browse files
committed
IWF-438: Validate if RPC method is not final
1 parent f786af8 commit 961c032

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.iworkflow.core;
2+
3+
// This indicates something goes wrong in the workflow definition
4+
public class ImplementationException extends RuntimeException {
5+
public ImplementationException(Throwable cause) {
6+
super(cause);
7+
}
8+
9+
public ImplementationException(String message) {
10+
super(message);
11+
}
12+
}

src/main/java/io/iworkflow/core/RpcDefinitions.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package io.iworkflow.core;
22

3-
import com.google.common.collect.ImmutableMap;
43
import io.iworkflow.core.communication.Communication;
54
import io.iworkflow.core.persistence.Persistence;
65

76
import java.io.Serializable;
87
import java.lang.reflect.Method;
9-
import java.util.Map;
8+
import java.lang.reflect.Modifier;
109

1110
public final class RpcDefinitions {
1211
private RpcDefinitions() {
@@ -100,12 +99,20 @@ public interface RpcProc0NoPersistence extends Serializable {
10099
void execute(Context context, Communication communication);
101100
}
102101

103-
public static final String ERROR_MESSAGE = "An RPC method must be in the form of one of {@link RpcDefinitions}";
102+
public static final String DEFINITION_ERROR_MESSAGE = "An RPC method must be in the form of one of {@link RpcDefinitions}";
103+
104+
public static final String FINAL_MODIFIER_ERROR_MESSAGE = "An RPC method must not be final";
104105

105106
public static void validateRpcMethod(final Method method) {
106107
RpcMethodMetadata methodMetadata = RpcMethodMatcher.match(method);
108+
final boolean isFinal = Modifier.isFinal(method.getModifiers());
109+
110+
if (isFinal) {
111+
throw new ImplementationException(FINAL_MODIFIER_ERROR_MESSAGE);
112+
}
113+
107114
if (methodMetadata == null) {
108-
throw new WorkflowDefinitionException(ERROR_MESSAGE);
115+
throw new WorkflowDefinitionException(DEFINITION_ERROR_MESSAGE);
109116
}
110117
}
111118
}

0 commit comments

Comments
 (0)