{"record":{"id":"fe4c0cb32ec2bf81","repo":"apache/flink","slug":"input-format-may-not-be-null","errorCode":null,"errorMessage":"Input format may not be null.","messagePattern":"Input format may not be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/GenericDataSourceBase.java","lineNumber":66,"sourceCode":"    protected final UserCodeWrapper<? extends T> formatWrapper;\n\n    protected String statisticsKey;\n\n    private SplitDataProperties splitProperties;\n\n    /**\n     * Creates a new instance for the given file using the given input format.\n     *\n     * @param format The {@link org.apache.flink.api.common.io.InputFormat} implementation used to\n     *     read the data.\n     * @param operatorInfo The type information for the operator.\n     * @param name The given name for the Pact, used in plans, logs and progress messages.\n     */\n    public GenericDataSourceBase(T format, OperatorInformation<OUT> operatorInfo, String name) {\n        super(operatorInfo, name);\n\n        if (format == null) {\n            throw new IllegalArgumentException(\"Input format may not be null.\");\n        }\n\n        this.formatWrapper = new UserCodeObjectWrapper<T>(format);\n    }\n\n    /**\n     * Creates a new instance for the given file using the given input format, using the default\n     * name.\n     *\n     * @param format The {@link org.apache.flink.api.common.io.InputFormat} implementation used to\n     *     read the data.\n     * @param operatorInfo The type information for the operator.\n     */\n    public GenericDataSourceBase(T format, OperatorInformation<OUT> operatorInfo) {\n        super(operatorInfo, DEFAULT_NAME);\n\n        if (format == null) {\n            throw new IllegalArgumentException(\"Input format may not be null.\");","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/GenericDataSourceBase.java#L48-L84","documentation":"Thrown by the GenericDataSourceBase(T format, OperatorInformation, String name) constructor when the supplied InputFormat instance is null. The source operator wraps user code, and a null format would cause an NPE later during plan traversal or execution, so it is rejected at construction time.","triggerScenarios":"Constructing a GenericDataSourceBase directly (rare in user code; usually internal/API-layer code) and passing a null InputFormat object, e.g. when a factory method returned null and the result was forwarded unchecked.","commonSituations":"Framework/library code building operators programmatically; a refactor where the format argument comes from a Map.get() that returns null; tests that stub the format supplier without a default.","solutions":["Ensure the InputFormat instance is created before constructing the source; never pass a value that may be null.","If the format is optional, return early / throw a clearer domain exception at the call site instead of relying on this guard.","Audit factory methods that produce the format argument for unchecked null returns."],"exampleFix":"// before\nInputFormat<OUT,?> fmt = registry.get(name);\nnew GenericDataSourceBase<>(fmt, opInfo, \"src\");\n// after\nInputFormat<OUT,?> fmt = registry.get(name);\nif (fmt == null) throw new IllegalStateException(\"No format registered for \" + name);\nnew GenericDataSourceBase<>(fmt, opInfo, \"src\");","handlingStrategy":"validation","validationCode":"if (format == null) throw new IllegalStateException(\"InputFormat not built for \" + name);\nnew GenericDataSourceBase<>(format, opInfo, name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never forward a possibly-null format into a constructor; guard at the call site.","Use Objects.requireNonNull(format, \"input format\") for a clear failure point.","Audit factory/supplier methods that produce formats for unchecked null returns."],"tags":["flink-core","data-source","constructor-null-check","input-format"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}