{"record":{"id":"46df106be3b94e0c","repo":"TheAlgorithms/Java","slug":"number-of-nodes-must-be-between-1-and-max-nodes","errorCode":null,"errorMessage":"Number of nodes must be between 1 and  + MAX_NODES","messagePattern":"Number of 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":46,"sourceCode":"\n    private static final int MAX_NODES = 10;\n    private static final double DEFAULT_DAMPING_FACTOR = 0.85;\n    private static final int DEFAULT_ITERATIONS = 2;\n\n    private int[][] adjacencyMatrix;\n    private double[] pageRankValues;\n    private int nodeCount;\n\n    /**\n     * Constructor to initialize PageRank with specified number of nodes\n     *\n     * @param numberOfNodes the number of nodes/pages in the graph\n     * @throws IllegalArgumentException if numberOfNodes is less than 1 or greater\n     *                                  than MAX_NODES\n     */\n    public PageRank(int numberOfNodes) {\n        if (numberOfNodes < 1 || numberOfNodes > MAX_NODES) {\n            throw new IllegalArgumentException(\"Number of nodes must be between 1 and \" + MAX_NODES);\n        }\n        this.nodeCount = numberOfNodes;\n        this.adjacencyMatrix = new int[MAX_NODES][MAX_NODES];\n        this.pageRankValues = new double[MAX_NODES];\n    }\n\n    /**\n     * Default constructor for interactive mode\n     */\n    public PageRank() {\n        this.adjacencyMatrix = new int[MAX_NODES][MAX_NODES];\n        this.pageRankValues = new double[MAX_NODES];\n    }\n\n    /**\n     * Main method for interactive PageRank calculation\n     *\n     * @param args command line arguments (not used)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/PageRank.java#L28-L64","documentation":"Thrown by the PageRank constructor when numberOfNodes is outside [1, MAX_NODES] (MAX_NODES = 10). The implementation uses fixed MAX_NODES-sized adjacency and PageRank arrays, so node counts above 10 overflow those buffers and counts below 1 are meaningless; both are rejected.","triggerScenarios":"Constructing new PageRank(n) with n < 1 or n > 10 (e.g. n = 0 or n = 25).","commonSituations":"Passing a graph larger than 10 nodes to this intentionally small implementation; an empty graph (0 nodes) from an empty input; dynamic graph sizes exceeding the hard-coded cap.","solutions":["Limit the graph to at most 10 nodes before constructing, or pick a different PageRank implementation without a hard cap.","Ensure numberOfNodes is at least 1; reject empty graphs upstream.","If you need more than 10 nodes, fork/extend the class to raise MAX_NODES (it is a compile-time constant).","Validate the count against [1, 10] at the data-loading boundary."],"exampleFix":"// before\nnew PageRank(graph.size()); // graph.size() may be 0 or 25\n\n// after\nif (graph.size() < 1 || graph.size() > 10) {\n    throw new IllegalArgumentException(\"This PageRank supports 1..10 nodes; got \" + graph.size());\n}\nnew PageRank(graph.size());","handlingStrategy":"validation","validationCode":"if (numberOfNodes < 1 || numberOfNodes > 10) {\n    throw new IllegalArgumentException(\"node count must be in [1, 10]; got \" + numberOfNodes);\n}\nnew PageRank(numberOfNodes);","typeGuard":"public static boolean isSupportedNodeCount(int n) {\n    return n >= 1 && n <= 10;\n}","tryCatchPattern":"try {\n    pr = new PageRank(n);\n} catch (IllegalArgumentException e) {\n    // cap at 10 or use a different implementation for larger graphs\n    throw e;\n}","preventionTips":["This implementation caps at 10 nodes; validate against [1, 10].","For larger graphs, choose a PageRank without a hard-coded MAX_NODES.","Reject empty graphs (0 nodes) upstream."],"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"}