{"record":{"id":"6706058f8bb2950d","repo":"apache/flink","slug":"failed-to-create-reader","errorCode":null,"errorMessage":"Failed to create reader","messagePattern":"Failed to create reader","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/hybrid/HybridSourceReader.java","lineNumber":226,"sourceCode":"        if (currentReader != null) {\n            try {\n                currentReader.close();\n            } catch (Exception e) {\n                throw new RuntimeException(\"Failed to close current reader\", e);\n            }\n            LOG.debug(\n                    \"Reader closed: subtask={} sourceIndex={} currentReader={}\",\n                    readerContext.getIndexOfSubtask(),\n                    currentSourceIndex,\n                    currentReader);\n        }\n        // TODO: track previous readers splits till checkpoint\n        Source source = switchedSources.sourceOf(index);\n        SourceReader<T, ?> reader;\n        try {\n            reader = source.createReader(readerContext);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to create reader\", e);\n        }\n        // currentReader must be switched before `addSplits` is called.\n        currentSourceIndex = index;\n        currentReader = reader;\n        // add restored splits\n        if (!restoredSplits.isEmpty()) {\n            List<HybridSourceSplit> splits = new ArrayList<>(restoredSplits.size());\n            Iterator<HybridSourceSplit> it = restoredSplits.iterator();\n            while (it.hasNext()) {\n                HybridSourceSplit hybridSplit = it.next();\n                if (hybridSplit.sourceIndex() == index) {\n                    splits.add(hybridSplit);\n                    it.remove();\n                }\n            }\n            addSplits(splits);\n        }\n","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-connector-base/src/main/java/org/apache/flink/connector/base/source/hybrid/HybridSourceReader.java#L208-L244","documentation":"Thrown as a RuntimeException by HybridSourceReader.setCurrentReader when calling source.createReader(readerContext) for the next source in the hybrid pipeline throws an exception. After closing the previous reader, setCurrentReader instantiates the new SourceReader; any failure during reader creation (misconfiguration, missing resources, initialization error) is wrapped and rethrown.","triggerScenarios":"HybridSource transitions to source index N, and switchedSources.sourceOf(N).createReader(context) throws — e.g., the source factory cannot connect to the external system, required configuration is missing, or the source implementation has a bug in its constructor.","commonSituations":"The next source in the HybridSource chain has incorrect connection configuration (e.g., wrong Kafka brokers, missing credentials); the source's createReader requires resources not available at transition time; switchedSources does not contain the expected source at the given index; custom source init code throws.","solutions":["Check the wrapped exception cause to identify what failed in createReader — it is typically the source-specific initialization error.","Verify the configuration for the failing source in the HybridSource chain (connection strings, credentials, etc.).","Ensure switchedSources is correctly populated with all sources in the pipeline via HybridSourceSource.switchedSources.","If the error is environmental (e.g., external system temporarily unavailable), the job failover mechanism will retry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate source configuration before building HybridSource\nSource<?, ?, ?> nextSource = sources.get(nextIndex);\nif (nextSource == null) {\n    throw new IllegalArgumentException(\"No source configured at index \" + nextIndex);\n}\n// Test reader creation in a try-with-resources\ntry (SourceReader<?, ?> testReader = nextSource.createReader(testContext)) {\n    // reader created successfully\n}","typeGuard":null,"tryCatchPattern":"// This error occurs internally in HybridSourceReader; handle at job level\ntry {\n    env.execute(\"hybridSourceJob\");\n} catch (Exception e) {\n    Throwable cause = ExceptionUtils.findThrowable(e, RuntimeException.class).orElse(e);\n    if (cause.getMessage() != null && cause.getMessage().equals(\"Failed to create reader\")) {\n        // check the wrapped cause for the source-specific initialization error\n        log.error(\"Reader creation failed for source in chain: {}\", cause.getCause());\n    }\n}","preventionTips":["Validate all source configurations in the HybridSource chain before deployment.","Ensure switchedSources contains all sources at their expected indices.","Test each source's createReader independently before composing in HybridSource."],"tags":["hybrid-source","source-reader","initialization","source-transition"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}