{"record":{"id":"9d19e8a1ac3159c2","repo":"TheAlgorithms/Java","slug":"adjacency-list-must-not-contain-null-sets","errorCode":null,"errorMessage":"Adjacency list must not contain null sets","messagePattern":"Adjacency list must not contain null sets","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/graph/BronKerbosch.java","lineNumber":41,"sourceCode":"    /**\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            }\n            graph.add(copy);\n        }\n\n        Set<Integer> r = new HashSet<>();\n        Set<Integer> p = new HashSet<>();\n        Set<Integer> x = new HashSet<>();\n        for (int v = 0; v < n; v++) {\n            p.add(v);","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/graph/BronKerbosch.java#L23-L59","documentation":"Thrown by BronKerbosch.findMaximalCliques when any entry adjacency.get(u) is null. The method iterates each vertex's neighbor set; a null set NPEs on iteration. Message: 'Adjacency list must not contain null sets'.","triggerScenarios":"A vertex with no neighbors represented as null instead of an empty set; a list built with some slots left null; sparse adjacency where isolated vertices were skipped.","commonSituations":"Building adjacency by adding only connected vertices; deserializing a sparse map into a list with gaps; arrays.asList with null elements.","solutions":["Represent every vertex's neighbor set, using an empty Set for isolated vertices.","Normalize the adjacency list: replace null entries with empty sets before calling.","Build the list with a fixed size and fill every slot."],"exampleFix":"// before\nList<Set<Integer>> adj = Arrays.asList(null, Set.of(1,2));\n\n// after\nList<Set<Integer>> adj = new ArrayList<>();\nadj.add(new HashSet<>()); // vertex 0 isolated\nadj.add(new HashSet<>(Set.of(0,2)));","handlingStrategy":"validation","validationCode":"for (int u = 0; u < adjacency.size(); u++) {\n    if (adjacency.get(u) == null) adjacency.set(u, new HashSet<>());\n}","typeGuard":"adjacency.stream().allMatch(Objects::nonNull)","tryCatchPattern":null,"preventionTips":["Represent isolated vertices with an empty Set, never null.","Allocate the list with fixed size and fill every slot.","Normalize sparse input before building adjacency."],"tags":["null-check","graph","input-validation","list"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}