apache/dolphinscheduler · error · ServiceException

NEGTIVE_SIZE_NUMBER_ERROR

NEGTIVE_SIZE_NUMBER_ERROR

Error message

NEGTIVE_SIZE_NUMBER_ERROR: size parameter {0} cannot be negative

What it means

Thrown by queryTopNLongestRunningWorkflowInstance when the 'size' parameter is negative. Size controls how many top-N longest running workflow instances are returned, and a negative count is rejected as an invalid query parameter before any data access.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java:182

    @Autowired
    private TaskInstanceContextDao taskInstanceContextDao;

    @Autowired
    private TaskDatasourcePermissionChecker taskDatasourcePermissionChecker;

    @Autowired
    private TaskSubWorkflowPermissionChecker taskSubWorkflowPermissionChecker;

    @Override
    public List<WorkflowInstanceSummaryVO> queryTopNLongestRunningWorkflowInstance(User loginUser, long projectCode,
                                                                                   int size,
                                                                                   String startTime, String endTime) {
        Project project = projectDao.queryByCode(projectCode);
        // check user access for project
        projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_INSTANCE);

        if (0 > size) {
            throw new ServiceException(Status.NEGTIVE_SIZE_NUMBER_ERROR, size);
        }
        if (Objects.isNull(startTime)) {
            throw new ServiceException(Status.DATA_IS_NULL, Constants.START_TIME);
        }
        Date start = DateUtils.stringToDate(startTime);
        if (Objects.isNull(endTime)) {
            throw new ServiceException(Status.DATA_IS_NULL, Constants.END_TIME);
        }
        Date end = DateUtils.stringToDate(endTime);
        if (start == null || end == null) {
            throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE);
        }
        if (start.getTime() > end.getTime()) {
            throw new ServiceException(Status.START_TIME_BIGGER_THAN_END_TIME_ERROR, startTime, endTime);
        }

        return workflowInstanceDao.queryTopNWorkflowInstance(size, start, end, WorkflowExecutionStatus.SUCCESS,
                projectCode)

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Pass a positive size (e.g., 10) in the request.
  2. Clamp the value in the caller: Math.max(1, size) before invoking the API.
  3. Fix scripts that compute size by subtraction; guard the expression.
  4. Validate query parameters client-side before sending.

Example fix

// before
int size = end - start; // can be negative
api.queryTopNLongestRunningWorkflowInstance(user, projectCode, size, ...);
// after
int size = Math.max(1, end - start);
api.queryTopNLongestRunningWorkflowInstance(user, projectCode, size, ...);
Defensive patterns

Strategy: validation

Validate before calling

// caller-side, before invoking the API
if (size < 0) {
    throw new IllegalArgumentException("size must be >= 0, got " + size);
}

Type guard

boolean isValidSize(Integer size) {
    return size != null && size >= 0;
}

Try / catch

try {
    service.queryTopNLongestRunningWorkflowInstance(user, projectCode, size, startTime, endTime);
} catch (ServiceException e) {
    if (e.getCode() == Status.NEGTIVE_SIZE_NUMBER_ERROR.getCode()) {
        // clamp and retry: size = Math.max(0, size)
    } else throw e;
}

Prevention

When it happens

Trigger: GET workflow-instance/top-N (queryTopNLongestRunningWorkflowInstance) with size=-1 or any negative value in query params; scripts computing size as (a-b) that can go negative; UI pagination bugs passing -pageSize.

Common situations: Monitoring dashboards with misconfigured page-size variables; shell scripts subtracting durations to derive size; API testing with sentinel negative values.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/97328f9b3b913265. Report an issue: GitHub.