{"record":{"id":"6ef827076f3e14d2","repo":"apache/seatunnel","slug":"already-an-mdcsupplier","errorCode":null,"errorMessage":"Already an MDCSupplier","messagePattern":"Already an MDCSupplier","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-api/src/main/java/org/apache/seatunnel/api/tracing/MDCTracer.java","lineNumber":203,"sourceCode":"\n    public static <T> MDCComparator<T> tracing(MDCContext context, Comparator<T> delegate) {\n        if (delegate instanceof MDCComparator) {\n            throw new IllegalArgumentException(\"Already an MDCComparator\");\n        }\n        return new MDCComparator<>(context, delegate);\n    }\n\n    public static <T> MDCSupplier<T> tracing(Supplier<T> delegate) {\n        return tracing(MDCContext.current(), delegate);\n    }\n\n    public static <T> MDCSupplier<T> tracing(Long jobId, Supplier<T> delegate) {\n        return tracing(MDCContext.of(jobId), delegate);\n    }\n\n    public static <T> MDCSupplier<T> tracing(MDCContext context, Supplier<T> delegate) {\n        if (delegate instanceof MDCSupplier) {\n            throw new IllegalArgumentException(\"Already an MDCSupplier\");\n        }\n        return new MDCSupplier<>(context, delegate);\n    }\n\n    public static <T> MDCStream<T> tracing(Stream<T> delegate) {\n        return tracing(MDCContext.current(), delegate);\n    }\n\n    public static <T> MDCStream<T> tracing(Long jobId, Stream<T> delegate) {\n        return tracing(MDCContext.of(jobId), delegate);\n    }\n\n    public static <T> MDCStream<T> tracing(MDCContext context, Stream<T> delegate) {\n        if (delegate instanceof MDCStream) {\n            throw new IllegalArgumentException(\"Already an MDCStream\");\n        }\n        return new MDCStream<>(context, delegate);\n    }","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-api/src/main/java/org/apache/seatunnel/api/tracing/MDCTracer.java#L185-L221","documentation":"MDCTracer.tracing(MDCContext, Supplier) wraps a plain Supplier in an MDCSupplier so trace context (jobId) propagates via MDC during supply(). It refuses to double-wrap: if the delegate is already an MDCSupplier it throws IllegalArgumentException, since wrapping again would nest contexts and defeat the tracing contract.","triggerScenarios":"Calling MDCTracer.tracing(context, supplier) where the supplier argument is already an instance of MDCSupplier — typically when tracing is applied twice, e.g. a supplier created by tracing(jobId, s) is later passed to tracing again.","commonSituations":"Pipelining supplier factories that each add tracing; refactoring code where an upstream layer already wrapped the supplier; caching a traced supplier and re-tracing it in a second component.","solutions":["Pass the already-wrapped MDCSupplier directly instead of re-tracing it (MDCSupplier IS-A Supplier, so it can be used as-is)","Remove the redundant tracing() call at one of the two layers","Unwrap the delegate first if you need to change the context, e.g. use MDCTracer.tracing(newContext, existingSupplier.getDelegate()) if available"],"exampleFix":"// before\nSupplier<String> traced = MDCTracer.tracing(jobId, supplier);\nSupplier<String> again = MDCTracer.tracing(jobId, traced); // throws\n// after\nSupplier<String> traced = MDCTracer.tracing(jobId, supplier); // wrap once","handlingStrategy":"type-guard","validationCode":"if (!(supplier instanceof MDCSupplier)) { supplier = MDCTracer.tracing(jobId, supplier); }","typeGuard":"static <T> Supplier<T> ensureTraced(Supplier<T> s, Long jobId) { return s instanceof MDCSupplier ? s : MDCTracer.tracing(jobId, s); }","tryCatchPattern":"try { return MDCTracer.tracing(jobId, supplier); } catch (IllegalArgumentException e) { return (MDCSupplier<T>) supplier; }","preventionTips":["Wrap once at the pipeline boundary, not at every layer","Use a helper like ensureTraced instead of calling tracing unconditionally","Search call graph for multiple tracing() applications to the same supplier"],"tags":["tracing","mdc","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}