Skip to content

Commit

Permalink
IWF-438: Validate if RPC method is not final
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Dec 30, 2024
1 parent f786af8 commit d33573e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/java/io/iworkflow/core/ImplementationException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.iworkflow.core;

// This indicates issues in the implementation of the workflow
public class ImplementationException extends RuntimeException {
public ImplementationException(Throwable cause) {
super(cause);
}

public ImplementationException(String message) {
super(message);
}
}
15 changes: 11 additions & 4 deletions src/main/java/io/iworkflow/core/RpcDefinitions.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.iworkflow.core;

import com.google.common.collect.ImmutableMap;
import io.iworkflow.core.communication.Communication;
import io.iworkflow.core.persistence.Persistence;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Map;
import java.lang.reflect.Modifier;

public final class RpcDefinitions {
private RpcDefinitions() {
Expand Down Expand Up @@ -100,12 +99,20 @@ public interface RpcProc0NoPersistence extends Serializable {
void execute(Context context, Communication communication);
}

public static final String ERROR_MESSAGE = "An RPC method must be in the form of one of {@link RpcDefinitions}";
public static final String DEFINITION_ERROR_MESSAGE = "An RPC method must be in the form of one of {@link RpcDefinitions}";

public static final String FINAL_MODIFIER_ERROR_MESSAGE = "An RPC method must not be final";

public static void validateRpcMethod(final Method method) {
RpcMethodMetadata methodMetadata = RpcMethodMatcher.match(method);
final boolean isFinal = Modifier.isFinal(method.getModifiers());

if (isFinal) {
throw new ImplementationException(FINAL_MODIFIER_ERROR_MESSAGE);
}

if (methodMetadata == null) {
throw new WorkflowDefinitionException(ERROR_MESSAGE);
throw new WorkflowDefinitionException(DEFINITION_ERROR_MESSAGE);
}
}
}

0 comments on commit d33573e

Please sign in to comment.