{"record":{"id":"32539bc6063ac5aa","repo":"TheAlgorithms/Java","slug":"successors-must-not-be-null","errorCode":null,"errorMessage":"successors must not be null","messagePattern":"successors must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/graph/PredecessorConstrainedDfs.java","lineNumber":82,"sourceCode":"        }\n    }\n\n    /**\n     * DFS (recursive) that records the order of first visit starting at {@code start},\n     * but only recurses to a child when <b>all</b> its predecessors have been visited.\n     * If a child is encountered early (some parent unvisited), a SKIP event is recorded.\n     *\n     * <p>Equivalent idea to the Python pseudo in the user's description (with successors and predecessors),\n     * but implemented in Java and returning a sequence of {@link TraversalEvent}s.</p>\n     *\n     * @param successors adjacency list: for each node, its outgoing neighbors\n     * @param start start node\n     * @return immutable list of traversal events (VISITs with monotonically increasing order and SKIPs with messages)\n     * @throws IllegalArgumentException if {@code successors} is null\n     */\n    public static <T> List<TraversalEvent<T>> dfsRecursiveOrder(Map<T, List<T>> successors, T start) {\n        if (successors == null) {\n            throw new IllegalArgumentException(\"successors must not be null\");\n        }\n        // derive predecessors once\n        Map<T, List<T>> predecessors = derivePredecessors(successors);\n        return dfsRecursiveOrder(successors, predecessors, start);\n    }\n\n    /**\n     * Same as {@link #dfsRecursiveOrder(Map, Object)} but with an explicit predecessors map.\n     */\n    public static <T> List<TraversalEvent<T>> dfsRecursiveOrder(Map<T, List<T>> successors, Map<T, List<T>> predecessors, T start) {\n\n        if (successors == null || predecessors == null) {\n            throw new IllegalArgumentException(\"successors and predecessors must not be null\");\n        }\n        if (start == null) {\n            return List.of();\n        }\n        if (!successors.containsKey(start) && !appearsAnywhere(successors, start)) {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/graph/PredecessorConstrainedDfs.java#L64-L100","documentation":"PredecessorConstrainedDfs.dfsRecursiveOrder(successors, start) throws this IllegalArgumentException when the successors adjacency map is null. The single-argument overload derives predecessors internally, so it only needs to guard the successors parameter.","triggerScenarios":"Calling dfsRecursiveOrder(null, start) with a null adjacency map.","commonSituations":"Graph not yet built when the traversal is triggered. A field left null after failed initialization. Optional/empty graph represented as null instead of an empty map.","solutions":["Pass an empty map (Collections.emptyMap()) instead of null for a trivial graph.","Ensure the successors map is constructed before the DFS call.","Add a null guard returning an empty event list."],"exampleFix":"// before\nList<TraversalEvent<T>> events = PredecessorConstrainedDfs.dfsRecursiveOrder(successors, start);\n\n// after\nMap<T, List<T>> succ = successors != null ? successors : Map.of();\nList<TraversalEvent<T>> events = PredecessorConstrainedDfs.dfsRecursiveOrder(succ, start);","handlingStrategy":"validation","validationCode":"if (successors == null) {\n    successors = java.util.Collections.emptyMap();\n}","typeGuard":"boolean hasSuccessors(Map<?,?> succ) { return succ != null; }","tryCatchPattern":null,"preventionTips":["Pass an empty map instead of null for trivial graphs.","Initialize the adjacency map before the DFS call.","Centralize graph construction to avoid null fields."],"tags":["graph-algorithm","argument-validation","null-check","dfs"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}