Skip to content

Commit

Permalink
fix nullpoint when task.getInput() is null (#93)
Browse files Browse the repository at this point in the history
* fix when task.getInput() is null

---------

Co-authored-by: zeyu10 <zeyu10@staff.sina.com>
  • Loading branch information
techloghub and zeyu10 authored Nov 13, 2024
1 parent e22df46 commit d4d1893
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,11 @@ private void processOutputMappingsWhenGetDescriptor(BaseTask task) {
*/
private void processInputMappingsWhenGetDescriptor(BaseTask task) {
List<Mapping> inputMappings = task.getInputMappings();
if (CollectionUtils.isEmpty(inputMappings)) {
Map<String, Object> taskInput = task.getInput();
if (CollectionUtils.isEmpty(inputMappings) || MapUtils.isEmpty(taskInput)) {
return;
}
Set<String> inputTargets = task.getInput().keySet().stream()
Set<String> inputTargets = taskInput.keySet().stream()
.map(key -> INPUT_PREFIX + key).collect(Collectors.toSet());

List<Mapping> filteredMappings = inputMappings.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,47 @@ class DAGDescriptorConverterImplTest extends Specification {
descriptor.contains("name: \"taskB\"")
descriptor.contains("body.data: \"\$.taskA.output.data\"")
}

def "fix null point exception when task.input is null"() {
given:
String descriptor = "workspace: default\n" +
"dagName: testGenerateOutputMappings\n" +
"alias: release\n" +
"type: flow\n" +
"tasks:\n" +
" - name: functionA\n" +
" category: function\n" +
" resourceName: http://test.url\n" +
" requestType: POST\n" +
" pattern: task_sync\n" +
" next: functionB\n" +
" inputMappings:\n" +
" - source: hello\n" +
" target: \$.input.body.world\n" +
" resourceProtocol: http\n" +
" - name: functionB\n" +
" category: function\n" +
" resourceName: http://test.url\n" +
" requestType: POST\n" +
" input:\n" +
" body.elements: \$.functionA.elements.*.name\n" +
" body.first_id: \$.functionA.elements[0].id\n" +
" resourceProtocol: http\n" +
" pattern: task_sync\n"
when:
DAG originDag = converter.convertDescriptorPOToDAG(new DescriptorPO(descriptor))
DescriptorVO descriptorVO = converter.convertDAGToDescriptorVO(originDag)
DAG dag = dagParser.parse(descriptorVO.getDescriptor())
then:
dag.tasks.forEach { task -> {
if (task.getName() == "functionA") {
assert task.getInputMappings().size() == 1
assert task.getInput() == null
} else {
assert task.getInputMappings() == null
assert task.getInput().size() == 2
}
}
}
}
}

0 comments on commit d4d1893

Please sign in to comment.