{"record":{"id":"31d91831c3e310ea","repo":"TheAlgorithms/Java","slug":"segment-list-must-not-be-null","errorCode":null,"errorMessage":"Segment list must not be null","messagePattern":"Segment list must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/geometry/BentleyOttmann.java","lineNumber":164,"sourceCode":"            }\n            return cmp;\n        }\n    }\n\n    /**\n     * Finds all intersection points among a set of line segments.\n     *\n     * <p>An intersection point is reported when two or more segments cross or touch.\n     * For overlapping segments, only actual crossing/touching points are reported,\n     * not all points along the overlap.</p>\n     *\n     * @param segments list of line segments represented as pairs of points\n     * @return a set of intersection points where segments meet or cross\n     * @throws IllegalArgumentException if the list is null or contains null points\n     */\n    public static Set<Point2D.Double> findIntersections(List<Segment> segments) {\n        if (segments == null) {\n            throw new IllegalArgumentException(\"Segment list must not be null\");\n        }\n\n        Segment.segmentCounter = 0; // Reset counter\n        Set<Point2D.Double> intersections = new HashSet<>();\n        PriorityQueue<Event> eventQueue = new PriorityQueue<>();\n        TreeSet<Segment> status = new TreeSet<>(new StatusComparator());\n        Map<Point2D.Double, Event> eventMap = new HashMap<>();\n\n        // Initialize event queue with segment start and end points\n        for (Segment s : segments) {\n            Point2D.Double left = s.leftPoint();\n            Point2D.Double right = s.rightPoint();\n\n            Event startEvent = getOrCreateEvent(eventMap, left, EventType.START);\n            startEvent.addSegment(s);\n\n            Event endEvent = getOrCreateEvent(eventMap, right, EventType.END);\n            endEvent.addSegment(s);","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/geometry/BentleyOttmann.java#L146-L182","documentation":"Thrown by BentleyOttmann.findIntersections(List<Segment> segments) when the segments list itself is null. The method iterates the list to seed its event queue; a null list NPEs immediately, so it is rejected up front. Message: 'Segment list must not be null'.","triggerScenarios":"Passing null for the segments list; a list field left null because no segments were constructed; chaining from a method that returns null on no input.","commonSituations":"Geometry pipelines where the segment-extraction step produced nothing and returned null instead of an empty list; tests that forgot to build the list.","solutions":["Pass Collections.emptyList() instead of null when there are no segments.","Ensure the segment-source method never returns null (return empty list).","Guard with Objects.requireNonNull at the boundary."],"exampleFix":"// before\nSet<Point2D.Double> pts = BentleyOttmann.findIntersections(maybeNullList);\n\n// after\nList<Segment> segs = maybeNullList != null ? maybeNullList : Collections.emptyList();\nSet<Point2D.Double> pts = BentleyOttmann.findIntersections(segs);","handlingStrategy":"validation","validationCode":"List<Segment> segs = segments != null ? segments : Collections.emptyList();\nBentleyOttmann.findIntersections(segs);","typeGuard":"segments != null","tryCatchPattern":null,"preventionTips":["Make segment-source methods return empty list, not null.","Pass Collections.emptyList() for the no-segments case.","Guard at the boundary with Objects.requireNonNull."],"tags":["null-check","geometry","input-validation","list"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}