-
Notifications
You must be signed in to change notification settings - Fork 51
Return null rather than throwing exception when conversion fail #1222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import io.serverlessworkflow.api.types.func.TypedJavaContextFunction; | ||
| import io.serverlessworkflow.api.types.func.TypedJavaFilterFunction; | ||
| import io.serverlessworkflow.api.types.func.TypedPredicate; | ||
| import io.serverlessworkflow.impl.WorkflowModel; | ||
| import io.serverlessworkflow.impl.WorkflowPredicate; | ||
| import io.serverlessworkflow.impl.expressions.AbstractExpressionFactory; | ||
| import io.serverlessworkflow.impl.expressions.ExpressionDescriptor; | ||
|
|
@@ -44,20 +45,31 @@ public ObjectExpression buildExpression(ExpressionDescriptor descriptor) { | |
| if (value instanceof Function func) { | ||
| return (w, t, n) -> func.apply(n.asJavaObject()); | ||
| } else if (value instanceof TypedFunction func) { | ||
| return (w, t, n) -> func.function().apply(n.as(func.argClass()).orElseThrow()); | ||
| return (w, t, n) -> func.function().apply(convert(n, func.argClass())); | ||
| } else if (value instanceof JavaFilterFunction func) { | ||
| return (w, t, n) -> func.apply(n.asJavaObject(), w, t); | ||
| } else if (value instanceof TypedJavaFilterFunction func) { | ||
| return (w, t, n) -> func.function().apply(n.as(func.argClass()).orElseThrow(), w, t); | ||
| return (w, t, n) -> func.function().apply(convert(n, func.argClass()), w, t); | ||
| } else if (value instanceof JavaContextFunction func) { | ||
| return (w, t, n) -> func.apply(n.asJavaObject(), w); | ||
| } else if (value instanceof TypedJavaContextFunction func) { | ||
| return (w, t, n) -> func.function().apply(n.as(func.argClass()).orElseThrow(), w); | ||
| return (w, t, n) -> func.function().apply(convert(n, func.argClass()), w); | ||
| } else { | ||
| return (w, t, n) -> value; | ||
| } | ||
| } | ||
|
|
||
| private <T> T convert(WorkflowModel model, Class<T> argClass) { | ||
| return model.isNull() | ||
| ? null | ||
| : model | ||
| .as(argClass) | ||
| .orElseThrow( | ||
| () -> | ||
| new IllegalArgumentException( | ||
| "Cannot convert model " + model.asJavaObject() + " to class" + argClass)); | ||
| } | ||
|
|
||
| @Override | ||
| public int priority(ExpressionDescriptor descriptor) { | ||
|
Comment on lines
+71
to
74
|
||
| Object value = descriptor.asObject(); | ||
|
Comment on lines
+66
to
75
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
model.isNull() ? null : ...conversion path isn’t covered by tests. Adding a test that passes a null workflow/task output into a typed Java function and asserts the function receivesnull(and no exception is thrown) would prevent regressions.