{"record":{"id":"cc086dd83b36e0ba","repo":"ReactiveX/RxJava","slug":"errors-is-empty","errorCode":null,"errorMessage":"errors is empty","messagePattern":"errors is empty","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/exceptions/CompositeException.java","lineNumber":78,"sourceCode":"     *\n     * @throws IllegalArgumentException if <code>errors</code> is empty.\n     */\n    public CompositeException(@NonNull Iterable<? extends Throwable> errors) {\n        Set<Throwable> deDupedExceptions = new LinkedHashSet<>();\n        if (errors != null) {\n            for (Throwable ex : errors) {\n                if (ex instanceof CompositeException ce) {\n                    deDupedExceptions.addAll(ce.getExceptions());\n                } else {\n                    deDupedExceptions.add(Objects.requireNonNullElseGet(ex,\n                            () -> new NullPointerException(\"Throwable was null!\")));\n                }\n            }\n        } else {\n            deDupedExceptions.add(new NullPointerException(\"errors was null\"));\n        }\n        if (deDupedExceptions.isEmpty()) {\n            throw new IllegalArgumentException(\"errors is empty\");\n        }\n        List<Throwable> localExceptions = new ArrayList<>(deDupedExceptions);\n        this.exceptions = Collections.unmodifiableList(localExceptions);\n        this.message = exceptions.size() + \" exceptions occurred. \";\n    }\n\n    /**\n     * Retrieves the list of exceptions that make up the {@code CompositeException}.\n     *\n     * @return the exceptions that make up the {@code CompositeException}, as a {@link List} of {@link Throwable}s\n     */\n    @NonNull\n    public List<Throwable> getExceptions() {\n        return exceptions;\n    }\n\n    @Override\n    @NonNull","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/exceptions/CompositeException.java#L60-L96","documentation":"Thrown by the CompositeException constructor when, after flattening nested CompositeExceptions, replacing null elements with NullPointerException, and de-duplicating, the resulting exception list is empty. This is a programming error: a CompositeException must wrap at least one real cause. An empty input collection, or a collection containing only nulls/empty nested composites, triggers it.","triggerScenarios":"new CompositeException(emptyList()); new CompositeException(listOfNulls); passing a List that contains only a CompositeException whose own exceptions list is empty; building a composite from a stream/collect that filtered everything out.","commonSituations":"Aggregating errors from a fan-out operation where zero sub-tasks failed (the 'nothing went wrong' case is being incorrectly wrapped); collecting exceptions into a list inside a catch-all loop that may never append; defensive code that always wraps a (possibly empty) list.","solutions":["Before constructing a CompositeException, check that the list is non-empty and contains at least one non-null Throwable.","If the aggregation legitimately produced no errors, skip creating the CompositeException entirely (return success instead).","Filter nulls out of the list and verify size > 0 before passing it in.","Add a test: an empty list throws, a single-element list succeeds, a list of nulls becomes a single NullPointerException-wrapped cause (non-empty, so no throw)."],"exampleFix":"// before\nList<Throwable> errs = collectErrors(tasks);\nthrow new CompositeException(errs); // throws 'errors is empty' if errs is empty\n\n// after\nList<Throwable> errs = collectErrors(tasks);\nif (errs.isEmpty()) {\n    return Result.success();\n}\nthrow new CompositeException(errs);","handlingStrategy":"validation","validationCode":"void throwIfAny(List<Throwable> errors) {\n    List<Throwable> real = errors.stream()\n        .filter(Objects::nonNull)\n        .toList();\n    if (real.isEmpty()) return; // nothing to wrap\n    throw new CompositeException(real);\n}","typeGuard":null,"tryCatchPattern":"try {\n    throw new CompositeException(errors);\n} catch (IllegalArgumentException e) {\n    // 'errors is empty' -> there were no errors to report\n}","preventionTips":["Only build a CompositeException when at least one Throwable was actually collected.","Filter nulls from the list before construction.","Treat an empty aggregation result as success, not as an error to wrap."],"tags":["validation","argument","composite-exception","error-handling","rxjava"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}