{"record":{"id":"18b11da6fc3b96c1","repo":"apache/seatunnel","slug":"already-an-mdcpredicate","errorCode":null,"errorMessage":"Already an MDCPredicate","messagePattern":"Already an MDCPredicate","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-api/src/main/java/org/apache/seatunnel/api/tracing/MDCTracer.java","lineNumber":173,"sourceCode":"\n    public static <T, R> MDCFunction<T, R> tracing(MDCContext context, Function<T, R> delegate) {\n        if (delegate instanceof MDCFunction) {\n            throw new IllegalArgumentException(\"Already an MDCFunction\");\n        }\n        return new MDCFunction<>(context, delegate);\n    }\n\n    public static <T> MDCPredicate<T> tracing(Predicate<T> delegate) {\n        return tracing(MDCContext.current(), delegate);\n    }\n\n    public static <T> MDCPredicate<T> tracing(Long jobId, Predicate<T> delegate) {\n        return tracing(MDCContext.of(jobId), delegate);\n    }\n\n    public static <T> MDCPredicate<T> tracing(MDCContext context, Predicate<T> delegate) {\n        if (delegate instanceof MDCPredicate) {\n            throw new IllegalArgumentException(\"Already an MDCPredicate\");\n        }\n        return new MDCPredicate<>(context, delegate);\n    }\n\n    public static <T> MDCComparator<T> tracing(Comparator<T> delegate) {\n        return tracing(MDCContext.current(), delegate);\n    }\n\n    public static <T> MDCComparator<T> tracing(Long jobId, Comparator<T> delegate) {\n        return tracing(MDCContext.of(jobId), delegate);\n    }\n\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    }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-api/src/main/java/org/apache/seatunnel/api/tracing/MDCTracer.java#L155-L191","documentation":"MDCTracer.tracing(context, Predicate) rejects a delegate already wrapped as MDCPredicate with IllegalArgumentException, failing fast instead of stacking two MDC capture/restore layers around one predicate test.","triggerScenarios":"Calling tracing(jobId, predicate) or tracing(context, predicate) where predicate is already an MDCPredicate from an earlier tracing() call, e.g. filter predicates wrapped twice in a pipeline.","commonSituations":"Filter chains where both a DSL helper and the submission code trace the same Predicate; reusing library-provided traced predicates and wrapping again.","solutions":["Trace the Predicate only once; reuse the MDCPredicate directly","Guard with `if (p instanceof MDCPredicate) use it else tracing(...)`","Remove tracing from the inner helper layer"],"exampleFix":"// before\nMDCPredicate<T> p = MDCTracer.tracing(jobId, MDCTracer.tracing(jobId, pred));\n// after\nMDCPredicate<T> p = MDCTracer.tracing(jobId, pred);","handlingStrategy":"type-guard","validationCode":"MDCPredicate<T> safeWrap(Long jobId, Predicate<T> p) {\n    return p instanceof MDCPredicate ? (MDCPredicate<T>) p : MDCTracer.tracing(jobId, p);\n}","typeGuard":"boolean isWrapped(Predicate<?> p) {\n    return p instanceof MDCPredicate;\n}","tryCatchPattern":"try {\n    return MDCTracer.tracing(jobId, predicate);\n} catch (IllegalArgumentException e) {\n    return (MDCPredicate<T>) predicate;\n}","preventionTips":["Wrap predicates once where they are defined","Do not double-wrap predicates passed through DSL helpers","Check instanceof MDCPredicate before applying tracing"],"tags":["java","mdc","tracing","double-wrap"],"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"}