{"record":{"id":"d3b289134bc41796","repo":"apache/dolphinscheduler","slug":"limit-must-be-1-or-greater-than-0","errorCode":null,"errorMessage":"limit must be -1 or greater than 0","messagePattern":"limit must be -1 or greater than 0","errorType":"validation","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java","lineNumber":41,"sourceCode":"import org.apache.dolphinscheduler.dao.repository.TenantDao;\nimport org.apache.dolphinscheduler.plugin.storage.api.StorageOperator;\n\nimport org.springframework.stereotype.Component;\n\n@Component\npublic class FetchFileContentDtoValidator extends AbstractResourceValidator<FetchFileContentDto> {\n\n    public FetchFileContentDtoValidator(StorageOperator storageOperator, TenantDao tenantDao) {\n        super(storageOperator, tenantDao);\n    }\n\n    @Override\n    public void validate(FetchFileContentDto fetchFileContentDto) {\n        if (fetchFileContentDto.getSkipLineNum() < 0) {\n            throw new ServiceException(\"skipLineNum must be greater than or equal to 0\");\n        }\n        if (fetchFileContentDto.getLimit() != -1 && fetchFileContentDto.getLimit() <= 0) {\n            throw new ServiceException(\"limit must be -1 or greater than 0\");\n        }\n        String resourceFileAbsolutePath = fetchFileContentDto.getResourceFileAbsolutePath();\n        User loginUser = fetchFileContentDto.getLoginUser();\n\n        exceptionResourceAbsolutePathInvalidated(resourceFileAbsolutePath);\n        exceptionResourceIsNotFile(resourceFileAbsolutePath);\n        exceptionUserNoResourcePermission(loginUser, resourceFileAbsolutePath);\n        exceptionFileContentCannotFetch(resourceFileAbsolutePath);\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":52,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/validator/resource/FetchFileContentDtoValidator.java#L23-L52","documentation":"FetchFileContentDtoValidator.validate throws this ServiceException when limit is neither -1 (meaning 'return all remaining lines') nor a positive number, i.e. it is 0 or any negative value other than -1.","triggerScenarios":"Calling the read-file-content API with limit = 0, -2, or other invalid values; only limit == -1 and limit > 0 are accepted.","commonSituations":"Client using 0 as a sentinel for 'unlimited' instead of -1; broken pagination math yielding 0-sized pages; copy-pasted code from APIs where 0 means unlimited.","solutions":["Use limit = -1 to fetch the whole file, or a positive integer for paged reads.","Clamp client-side page sizes: ensure pageSize > 0 before building the request.","Map any 'unlimited' sentinel in your code to -1 before calling the API."],"exampleFix":"// before\nfetchFileContent(loginUser, path, 0, 0); // 0 rejected\n// after\nfetchFileContent(loginUser, path, 0, -1); // whole file\n// or\nfetchFileContent(loginUser, path, 0, 100); // first 100 lines","handlingStrategy":"validation","validationCode":"if (limit != -1 && limit <= 0) { throw new IllegalArgumentException(\"limit must be -1 or > 0\"); }","typeGuard":"boolean isValidLimit(int limit) { return limit == -1 || limit > 0; }","tryCatchPattern":null,"preventionTips":["Use -1 as the only sentinel for 'unlimited'; never 0.","Ensure computed page sizes are positive before sending requests.","Document limit semantics (-1 = all) in client SDK wrappers."],"tags":["validation","pagination","resource","dolphinscheduler"],"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-14T05:17:10.506Z"}