Skip to content

Commit 96ad788

Browse files
authored
IWF-518: Bypass constructor when using newRpcStub (#293)
1 parent b848651 commit 96ad788

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ dependencies {
6060
implementation 'io.swagger:swagger-core:1.6.6'
6161
implementation "org.openapitools:jackson-databind-nullable:0.2.1"
6262
implementation "net.bytebuddy:byte-buddy:1.14.4"
63+
implementation "org.objenesis:objenesis:3.4"
6364

6465
// jaskson
6566
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import net.bytebuddy.ByteBuddy;
2121
import net.bytebuddy.implementation.MethodDelegation;
2222
import net.bytebuddy.matcher.ElementMatchers;
23+
import org.objenesis.Objenesis;
24+
import org.objenesis.ObjenesisStd;
2325

2426
import java.lang.reflect.Constructor;
2527
import java.lang.reflect.InvocationTargetException;
@@ -802,21 +804,8 @@ public <T> T newRpcStub(Class<T> workflowClassForRpc, String workflowId, String
802804
.load(getClass().getClassLoader())
803805
.getLoaded();
804806

805-
T result;
806-
try {
807-
if(dynamicType.getConstructors().length ==0){
808-
throw new WorkflowDefinitionException("workflow must define at least a constructor");
809-
}
810-
final Constructor<?> constructor = dynamicType.getConstructors()[0];
811-
final int parameterCount = constructor.getParameterCount();
812-
final Object[] params = new Object[parameterCount];
813-
814-
result = (T) constructor.newInstance(params);
815-
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
816-
throw new IllegalStateException(e);
817-
}
818-
819-
return result;
807+
Objenesis objenesis = new ObjenesisStd();
808+
return (T) objenesis.newInstance(dynamicType);
820809
}
821810

822811
/**

0 commit comments

Comments
 (0)