Skip to content
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

Fix task def name npe #360

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,17 @@ public TaskDef getTaskDefinition() {
}

/**
* @param taskDefinition Task definition
* Sets the TaskDef for this instance. If the passed TaskDef does not have a name, this method
* will set it to the name of the current instance.
*
* <p>NOTE: This method mutates the passed TaskDef object.
*
* @param taskDefinition The TaskDef to set. It may be modified by this method.
*/
public void setTaskDefinition(TaskDef taskDefinition) {
if (taskDefinition != null && taskDefinition.getName() == null) {
taskDefinition.setName(this.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not expect a setX(X arg) to mutate the passed parameter. It’s not ideal to introduce side effects to a passed parameter.

Either avoid the side effect, document it clearly or create a copy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shaileshpadave can you check where is this being called from and the caller should fix this.

}
this.taskDefinition = taskDefinition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.junit.Test;

import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.tasks.TaskType;
import com.netflix.conductor.common.metadata.workflow.WorkflowTask;

Expand All @@ -29,6 +30,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class WorkflowTaskTest {
Expand Down Expand Up @@ -76,4 +78,24 @@ public void testWorkflowTaskName() {
validationErrors.contains(
"WorkflowTask taskReferenceName name cannot be empty or null"));
}

@Test
public void testSetTaskDefinition() {
WorkflowTask workflowTask = new WorkflowTask();
TaskDef taskDef = new TaskDef();

// Case 1: taskDefinition is not null and taskDefinition.getName() is null
taskDef.setName(null);
workflowTask.setTaskDefinition(taskDef);
assertEquals(workflowTask.getName(), taskDef.getName());

// Case 2: taskDefinition is not null and taskDefinition.getName() is not null
taskDef.setName("existingName");
workflowTask.setTaskDefinition(taskDef);
assertEquals("existingName", taskDef.getName());

// Case 3: taskDefinition is null
workflowTask.setTaskDefinition(null);
assertNull(workflowTask.getTaskDefinition());
}
}
Loading