{"record":{"id":"c385131273156cc1","repo":"TheAlgorithms/Java","slug":"edges-list-must-not-be-null-or-empty","errorCode":null,"errorMessage":"Edges list must not be null or empty","messagePattern":"Edges list must not be null or empty","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithm.java","lineNumber":50,"sourceCode":"    /**\n     * Represents the graph\n     */\n    static class Graph {\n        final int vertex;\n        final List<Edge> edges;\n\n        /**\n         * Constructor for the graph\n         *\n         * @param vertex number of vertices\n         * @param edges  list of edges\n         */\n        Graph(final int vertex, final List<Edge> edges) {\n            if (vertex < 0) {\n                throw new IllegalArgumentException(\"Number of vertices must be positive\");\n            }\n            if (edges == null || edges.isEmpty()) {\n                throw new IllegalArgumentException(\"Edges list must not be null or empty\");\n            }\n            for (final var edge : edges) {\n                checkEdgeVertices(edge.src, vertex);\n                checkEdgeVertices(edge.dest, vertex);\n            }\n\n            this.vertex = vertex;\n            this.edges = edges;\n        }\n    }\n\n    /**\n     * Represents a subset for Union-Find operations\n     */\n    private static class Component {\n        int parent;\n        int rank;\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/datastructures/graphs/BoruvkaAlgorithm.java#L32-L68","documentation":"Thrown by the BoruvkaAlgorithm.Graph constructor when the `edges` list is null or empty. Boruvka's algorithm builds a minimum spanning tree from edges, so an empty edge set is meaningless and the constructor refuses it; null is treated identically to guard against uninitialized inputs.","triggerScenarios":"Constructing the Graph with `null` for edges, `Collections.emptyList()`, or a list filtered down to zero elements (e.g. `edges.stream().filter(...).toList()`).","commonSituations":"Loading edge data from a file/network that returned nothing; a filter that removes all edges; forgetting to populate the list before constructing the graph.","solutions":["Ensure the edges list is populated before construction; load/generate edges first","If an empty graph is legitimately possible in your flow, short-circuit before constructing (Boruvka needs >=1 edge)","Replace null with an explicit non-empty list or fail earlier at the data-source step"],"exampleFix":"// before\nGraph g = new BoruvkaAlgorithm.Graph(n, edges);\n// after\nif (edges == null || edges.isEmpty()) {\n    throw new IllegalStateException(\"no edges loaded\");\n}\nGraph g = new BoruvkaAlgorithm.Graph(n, edges);","handlingStrategy":"validation","validationCode":"if (edges == null || edges.isEmpty()) {\n    throw new IllegalArgumentException(\"edges must be non-empty\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    new BoruvkaAlgorithm.Graph(v, edges);\n} catch (IllegalArgumentException e) {\n    // handle empty/null edges\n}","preventionTips":["Validate edge data at load time, not at construction time","Treat an empty edge set as a data-loading error rather than passing it through"],"tags":["graph","input-validation","null-check"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}