{"record":{"id":"110af38b45ed9714","repo":"TheAlgorithms/Java","slug":"total-nodes-must-be-between-1-and-max-nodes","errorCode":null,"errorMessage":"Total nodes must be between 1 and  + MAX_NODES","messagePattern":"Total nodes must be between 1 and  \\+ MAX_NODES","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/PageRank.java","lineNumber":185,"sourceCode":"        if (verbose) {\n            System.out.println(\"\\nFinal PageRank:\");\n            printPageRanks(totalNodes);\n        }\n\n        return pageRankValues.clone();\n    }\n\n    /**\n     * Validates input parameters for PageRank calculation\n     *\n     * @param totalNodes    the total number of nodes\n     * @param dampingFactor the damping factor\n     * @param iterations    number of iterations\n     * @throws IllegalArgumentException if parameters are invalid\n     */\n    private void validateInputParameters(int totalNodes, double dampingFactor, int iterations) {\n        if (totalNodes < 1 || totalNodes > MAX_NODES) {\n            throw new IllegalArgumentException(\"Total nodes must be between 1 and \" + MAX_NODES);\n        }\n        if (dampingFactor < 0 || dampingFactor > 1) {\n            throw new IllegalArgumentException(\"Damping factor must be between 0 and 1\");\n        }\n        if (iterations < 1) {\n            throw new IllegalArgumentException(\"Iterations must be at least 1\");\n        }\n    }\n\n    /**\n     * Initializes PageRank values for all nodes\n     *\n     * @param totalNodes      the total number of nodes\n     * @param initialPageRank the initial PageRank value\n     * @param verbose         whether to print output\n     */\n    private void initializePageRanks(int totalNodes, double initialPageRank, boolean verbose) {\n        for (int i = 1; i <= totalNodes; i++) {","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/PageRank.java#L167-L203","documentation":"Thrown by PageRank.validateInputParameters (called during calculation) when totalNodes is outside [1, MAX_NODES] (MAX_NODES = 10). This is the same node-count invariant enforced at construction but applied to the calculate path; it protects the fixed-size internal buffers.","triggerScenarios":"Triggering a calculate/step that internally calls validateInputParameters with totalNodes < 1 or totalNodes > 10; mismatch between the constructed nodeCount and a totalNodes argument passed to a calculation entry point.","commonSituations":"Passing a totalNodes argument inconsistent with the constructed size; loading a graph with more than 10 nodes; calling calculate with parameters derived from a different graph than the one used at construction.","solutions":["Keep totalNodes within [1, 10] and consistent with the nodeCount used at construction.","Source totalNodes from the same graph object used to build the PageRank instance.","Use a PageRank implementation without a hard cap for larger graphs.","Validate totalNodes at the boundary before invoking the calculation."],"exampleFix":"// before\npageRank.calc(graph.size(), damping, iterations); // graph.size() may be > 10\n\n// after\nint total = Math.max(1, Math.min(graph.size(), 10));\npageRank.calc(total, damping, iterations);","handlingStrategy":"validation","validationCode":"if (totalNodes < 1 || totalNodes > 10) {\n    throw new IllegalArgumentException(\"totalNodes must be in [1, 10]; got \" + totalNodes);\n}\npageRank.calc(totalNodes, dampingFactor, iterations);","typeGuard":"public static boolean isSupportedNodeCount(int n) {\n    return n >= 1 && n <= 10;\n}","tryCatchPattern":"try {\n    pageRank.calc(total, damping, iters);\n} catch (IllegalArgumentException e) {\n    total = Math.max(1, Math.min(total, 10));\n    pageRank.calc(total, damping, iters);\n}","preventionTips":["Keep totalNodes consistent with the constructed nodeCount.","Source totalNodes from the same graph used at construction.","Cap graphs at 10 nodes for this implementation."],"tags":["validation","pagerank","graph","input-validation","capacity"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}