{"record":{"id":"50eb40d09e218213","repo":"opendataloader-project/opendataloader-pdf","slug":"invalid-page-range-format-s-expected-format","errorCode":null,"errorMessage":"Invalid page range format: '%s'. Expected format: 1,3,5-7","messagePattern":"Invalid page range format: '(.+?)'\\. Expected format: 1,3,5-7","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/opendataloader-pdf-core/src/main/java/org/opendataloader/pdf/api/Config.java","lineNumber":751,"sourceCode":"        }\n        return new ArrayList<>(cachedPageNumbers);\n    }\n\n    /**\n     * Parses a page range specification into a list of page numbers.\n     *\n     * @param pages The page specification (e.g., \"1,3,5-7\").\n     * @return List of 1-based page numbers.\n     * @throws IllegalArgumentException if the format is invalid.\n     */\n    private static List<Integer> parsePageRanges(String pages) {\n        List<Integer> result = new ArrayList<>();\n        String[] parts = pages.split(\",\");\n\n        for (String part : parts) {\n            String trimmed = part.trim();\n            if (trimmed.isEmpty()) {\n                throw new IllegalArgumentException(String.format(INVALID_PAGE_RANGE_FORMAT, pages));\n            }\n\n            if (trimmed.contains(\"-\")) {\n                parseRange(trimmed, pages, result);\n            } else {\n                parseSinglePage(trimmed, pages, result);\n            }\n        }\n\n        return result;\n    }\n\n    private static void parseRange(String range, String fullInput, List<Integer> result) {\n        String[] parts = range.split(\"-\", SPLIT_KEEP_EMPTY_TRAILING);\n        if (parts.length != 2 || parts[0].isEmpty() || parts[1].isEmpty()) {\n            throw new IllegalArgumentException(String.format(INVALID_PAGE_RANGE_FORMAT, fullInput));\n        }\n","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/opendataloader-project/opendataloader-pdf/blob/a7789b8e77dd05e2b8659eb3ea12fc458f80bfb8/java/opendataloader-pdf-core/src/main/java/org/opendataloader/pdf/api/Config.java#L733-L769","documentation":"parsePageRanges splits the --pages value on ',' and rejects any comma-separated token that is empty after trim. This catches consecutive commas, a leading comma, a trailing comma, and an entirely blank input. The whole original input string is reported, not just the bad token.","triggerScenarios":"config.setPages(\"1,,3\"), config.setPages(\"1,2,\"), config.setPages(\",1\"), or config.setPages(\"\") (splitting \"\" yields one empty token).","commonSituations":"Dynamically building the range string with String.join and an empty list element; trailing comma from user input; blank value passed from an unset env var.","solutions":["Sanitize the input: trim and drop empty tokens before joining (e.g. filter out blanks).","Validate the whole string with a regex like ^(\\d+|\\d+-\\d+)(,(\\d+|\\d+-\\d+))*$ before calling setPages.","Reject a blank/whitespace-only value upstream instead of forwarding it to setPages."],"exampleFix":"// before: config.setPages(String.join(\",\", userTokens));   // fails if a token is blank\n// after:  config.setPages(userTokens.stream().map(String::trim).filter(s -> !s.isEmpty()).collect(joining(\",\")));","handlingStrategy":"validation","validationCode":"// Reject empty/blank tokens and the empty string before calling setPages.\nString pages = rawPages == null ? null : rawPages.trim();\nif (pages == null || pages.isEmpty()) {\n    throw new IllegalArgumentException(\"--pages must not be blank\");\n}\nfor (String t : pages.split(\",\")) {\n    if (t.trim().isEmpty()) throw new IllegalArgumentException(\n        \"--pages has an empty token (consecutive/trailing comma): \" + pages);\n}\nconfig.setPages(pages);","typeGuard":"static final java.util.regex.Pattern PAGES =\n    java.util.regex.Pattern.compile(\"^(\\\\d+|\\\\d+-\\\\d+)(,(\\\\d+|\\\\d+-\\\\d+))*$\");\nstatic boolean isValidPagesSpec(String s) {\n    return s != null && PAGES.matcher(s.trim()).matches();\n}","tryCatchPattern":"try {\n    config.setPages(raw);\n} catch (IllegalArgumentException e) {\n    // report the expected format 1,3,5-7 and abort input handling\n}","preventionTips":["When building ranges dynamically, filter out blank tokens before joining.","Validate the whole spec with one regex covering singles and closed ranges."],"tags":["configuration","validation","pages","parsing"],"backgroundTag":null,"analyzedSha":"a7789b8e77dd05e2b8659eb3ea12fc458f80bfb8","analyzedAt":"2026-08-14T05:22:03.953Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}