datashare icon indicating copy to clipboard operation
datashare copied to clipboard

chore: improve TaskView encapsulation

Open ClemDoum opened this issue 9 months ago • 3 comments

Current behavior

Today, the signature of TaskFactoryHelper.createTaskCallable is:

public class TaskFactoryHelper {
    public static Callable<?> createTaskCallable(
        TaskFactory factory, String name, TaskView<?> taskView, Function<Double, Void> progress
    )  throws UnknownTask;
}

The issue with this signature is that implementer get a TaskView as input of their task, while they should only need the TaskView.properties. By providing the full TaskView<?> taskView to the implementer, we give the task implementer control over the taskView state. In particular implementers can access setError, setResult which should only be called by the datashare-tasks codebase.

Expected behavior and potential solutions

Task implementer should not be allowed to update the task state as this can have detrimental side effects.

Potential solutions:

  • make setResult, setError and other side effect methods package private so that only datashare-tasks can use them
  • update the TaskFactoryHelper.createTaskCallable to pass only the TaskView.properties

ClemDoum avatar May 27 '24 13:05 ClemDoum