{"record":{"id":"97328f9b3b913265","repo":"apache/dolphinscheduler","slug":"negtive-size-number-error","errorCode":"NEGTIVE_SIZE_NUMBER_ERROR","errorMessage":"NEGTIVE_SIZE_NUMBER_ERROR: size parameter {0} cannot be negative","messagePattern":"NEGTIVE_SIZE_NUMBER_ERROR: size parameter (.+?) cannot be negative","errorType":"validation","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java","lineNumber":182,"sourceCode":"    @Autowired\n    private TaskInstanceContextDao taskInstanceContextDao;\n\n    @Autowired\n    private TaskDatasourcePermissionChecker taskDatasourcePermissionChecker;\n\n    @Autowired\n    private TaskSubWorkflowPermissionChecker taskSubWorkflowPermissionChecker;\n\n    @Override\n    public List<WorkflowInstanceSummaryVO> queryTopNLongestRunningWorkflowInstance(User loginUser, long projectCode,\n                                                                                   int size,\n                                                                                   String startTime, String endTime) {\n        Project project = projectDao.queryByCode(projectCode);\n        // check user access for project\n        projectService.checkProjectAndAuthThrowException(loginUser, project, WORKFLOW_INSTANCE);\n\n        if (0 > size) {\n            throw new ServiceException(Status.NEGTIVE_SIZE_NUMBER_ERROR, size);\n        }\n        if (Objects.isNull(startTime)) {\n            throw new ServiceException(Status.DATA_IS_NULL, Constants.START_TIME);\n        }\n        Date start = DateUtils.stringToDate(startTime);\n        if (Objects.isNull(endTime)) {\n            throw new ServiceException(Status.DATA_IS_NULL, Constants.END_TIME);\n        }\n        Date end = DateUtils.stringToDate(endTime);\n        if (start == null || end == null) {\n            throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE);\n        }\n        if (start.getTime() > end.getTime()) {\n            throw new ServiceException(Status.START_TIME_BIGGER_THAN_END_TIME_ERROR, startTime, endTime);\n        }\n\n        return workflowInstanceDao.queryTopNWorkflowInstance(size, start, end, WorkflowExecutionStatus.SUCCESS,\n                projectCode)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java#L164-L200","documentation":"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.","triggerScenarios":"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.","commonSituations":"Monitoring dashboards with misconfigured page-size variables; shell scripts subtracting durations to derive size; API testing with sentinel negative values.","solutions":["Pass a positive size (e.g., 10) in the request.","Clamp the value in the caller: Math.max(1, size) before invoking the API.","Fix scripts that compute size by subtraction; guard the expression.","Validate query parameters client-side before sending."],"exampleFix":"// before\nint size = end - start; // can be negative\napi.queryTopNLongestRunningWorkflowInstance(user, projectCode, size, ...);\n// after\nint size = Math.max(1, end - start);\napi.queryTopNLongestRunningWorkflowInstance(user, projectCode, size, ...);","handlingStrategy":"validation","validationCode":"// caller-side, before invoking the API\nif (size < 0) {\n    throw new IllegalArgumentException(\"size must be >= 0, got \" + size);\n}","typeGuard":"boolean isValidSize(Integer size) {\n    return size != null && size >= 0;\n}","tryCatchPattern":"try {\n    service.queryTopNLongestRunningWorkflowInstance(user, projectCode, size, startTime, endTime);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.NEGTIVE_SIZE_NUMBER_ERROR.getCode()) {\n        // clamp and retry: size = Math.max(0, size)\n    } else throw e;\n}","preventionTips":["Clamp computed sizes with Math.max(0, value) before sending.","Validate pagination/query params in API clients and dashboards.","Use non-negative defaults (e.g., 10) instead of derived expressions that can go negative."],"tags":["query-parameter","negative-value","validation","workflow-instance"],"backgroundTag":"value-out-of-range","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}