{"record":{"id":"aac1313e060d967d","repo":"TheAlgorithms/Java","slug":"adjacency-list-must-not-be-null","errorCode":null,"errorMessage":"Adjacency list must not be null","messagePattern":"Adjacency list must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/graph/BronKerbosch.java","lineNumber":33,"sourceCode":" *\n * @author <a href=\"https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm\">Wikipedia: Bron–Kerbosch algorithm</a>\n */\npublic final class BronKerbosch {\n\n    private BronKerbosch() {\n    }\n\n    /**\n     * Finds all maximal cliques of the provided graph.\n     *\n     * @param adjacency adjacency list where {@code adjacency.size()} equals the number of vertices\n     * @return a list containing every maximal clique, each represented as a {@link Set} of vertices\n     * @throws IllegalArgumentException if the adjacency list is {@code null}, contains {@code null}\n     *         entries, or references invalid vertices\n     */\n    public static List<Set<Integer>> findMaximalCliques(List<Set<Integer>> adjacency) {\n        if (adjacency == null) {\n            throw new IllegalArgumentException(\"Adjacency list must not be null\");\n        }\n\n        int n = adjacency.size();\n        List<Set<Integer>> graph = new ArrayList<>(n);\n        for (int u = 0; u < n; u++) {\n            Set<Integer> neighbors = adjacency.get(u);\n            if (neighbors == null) {\n                throw new IllegalArgumentException(\"Adjacency list must not contain null sets\");\n            }\n            Set<Integer> copy = new HashSet<>();\n            for (int v : neighbors) {\n                if (v < 0 || v >= n) {\n                    throw new IllegalArgumentException(\"Neighbor index out of bounds: \" + v);\n                }\n                if (v != u) {\n                    copy.add(v);\n                }\n            }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/graph/BronKerbosch.java#L15-L51","documentation":"Thrown by BronKerbosch.findMaximalCliques(List<Set<Integer>> adjacency) when the adjacency list itself is null. The method reads adjacency.size() and indexes adjacency.get(u); a null list NPEs, so it is rejected up front. Message: 'Adjacency list must not be null'.","triggerScenarios":"Passing null for the adjacency list; a graph-construction step that returns null on empty input; uninitialized graph field.","commonSituations":"Graph builders that return null for an empty graph; tests missing the adjacency fixture; deserialization that maps an absent field to null.","solutions":["Construct an explicit adjacency list (even if empty) before calling.","Make the graph builder return an empty list for no-vertex graphs.","Guard with Objects.requireNonNull at the boundary."],"exampleFix":"// before\nList<Set<Integer>> cliques = BronKerbosch.findMaximalCliques(adj);\n\n// after\nList<Set<Integer>> adj = adjIn != null ? adjIn : new ArrayList<>();\nList<Set<Integer>> cliques = BronKerbosch.findMaximalCliques(adj);","handlingStrategy":"validation","validationCode":"List<Set<Integer>> adj = adjacency != null ? adjacency : new ArrayList<>();\nBronKerbosch.findMaximalCliques(adj);","typeGuard":"adjacency != null","tryCatchPattern":null,"preventionTips":["Graph builders should return an empty list for no vertices.","Normalize null adjacency to empty list before calling.","Guard at the boundary."],"tags":["null-check","graph","input-validation","list"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}