{"record":{"id":"2d478a6f15485d27","repo":"apache/seatunnel","slug":"reflect-class-operation-failed-2d478a","errorCode":"REFLECT_CLASS_OPERATION_FAILED","errorMessage":"Failed to instance [","messagePattern":"Failed to instance \\[","errorType":"error_code","errorClass":"JdbcConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/connection/DataSourceUtils.java","lineNumber":155,"sourceCode":"    private static Object loadDataSource(final String xaDataSourceClassName) {\n        Class<?> xaDataSourceClass;\n        try {\n            xaDataSourceClass =\n                    Thread.currentThread().getContextClassLoader().loadClass(xaDataSourceClassName);\n        } catch (final ClassNotFoundException ignored) {\n            try {\n                xaDataSourceClass = Class.forName(xaDataSourceClassName);\n            } catch (final ClassNotFoundException ex) {\n                throw new JdbcConnectorException(\n                        CommonErrorCodeDeprecated.CLASS_NOT_FOUND,\n                        \"Failed to load [\" + xaDataSourceClassName + \"]\",\n                        ex);\n            }\n        }\n        try {\n            return xaDataSourceClass.getDeclaredConstructor().newInstance();\n        } catch (final ReflectiveOperationException ex) {\n            throw new JdbcConnectorException(\n                    CommonErrorCodeDeprecated.REFLECT_CLASS_OPERATION_FAILED,\n                    \"Failed to instance [\" + xaDataSourceClassName + \"]\",\n                    ex);\n        }\n    }\n}\n","sourceCodeStart":137,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/connection/DataSourceUtils.java#L137-L162","documentation":"This error is thrown by DataSourceUtils.loadDataSource when instantiating a configured XADataSource class via reflection fails. SeaTunnel locates the xaDataSourceClassName, loads it, and calls getDeclaredConstructor().newInstance(); any ReflectiveOperationException (class not found, no-arg constructor missing, constructor throwing, illegal access) is wrapped in this JdbcConnectorException. It means the driver class could be named but not actually constructed, so XA (exactly-once) JDBC connections cannot be created.","triggerScenarios":"Calling DataSourceUtils.dataSource() with an xaDataSourceClassName whose class is absent from the runtime classpath/plugin dir, whose driver has no public no-arg constructor, or whose constructor throws (e.g. driver init fails due to missing native libs or wrong JDBC URL scheme for that driver).","commonSituations":"Driver jar not placed in $SEATUNNEL_HOME/connectors or lib directory so Class.forName-style loading partially succeeds but instantiation fails; typo in xaDataSourceClassName (e.g. com.mysql.jdbc.Driver vs com.mysql.cj.jdbc.Driver); using an old driver version removed in a JDBC driver upgrade; shading/classloader isolation preventing driver initialization.","solutions":["Add the correct JDBC driver jar to the SeaTunnel plugin/lib directory for the connector","Verify the xaDataSourceClassName exactly matches the driver's XADataSource class for your driver version","Check the wrapped 'Caused by' ReflectiveOperationException for the real cause (missing class, constructor exception, security) and fix that","If upgrading drivers, update the class name (e.g. MySQL 5.x com.mysql.jdbc.Driver -> 8.x com.mysql.cj.jdbc.Driver)"],"exampleFix":"// before\nurl = \"jdbc:mysql://localhost:3306/test\"\nxaDataSourceClassName = \"com.mysql.jdbc.Driver\"   // wrong: this is a Driver, and 8.x removed it\n// after\nxaDataSourceClassName = \"com.mysql.cj.jdbc.MysqlXADataSource\"","handlingStrategy":"validation","validationCode":"String cls = cfg.getXaDataSourceClassName();\ntry {\n    Class<?> c = Class.forName(cls, true, Thread.currentThread().getContextClassLoader());\n    c.getDeclaredConstructor(); // must have a public no-arg constructor\n    if (!javax.sql.XADataSource.class.isAssignableFrom(c)) throw new IllegalStateException(cls + \" is not an XADataSource\");\n} catch (ReflectiveOperationException | IllegalStateException e) {\n    throw new IllegalArgumentException(\"Bad xaDataSourceClassName: \" + cls, e);\n}","typeGuard":"boolean isValidXaDataSource(String name) {\n    try {\n        Class<?> c = Class.forName(name, true, Thread.currentThread().getContextClassLoader());\n        return javax.sql.XADataSource.class.isAssignableFrom(c)\n            && java.lang.reflect.Modifier.isPublic(c.getModifiers());\n    } catch (ClassNotFoundException e) { return false; }\n}","tryCatchPattern":"try {\n    ds = DataSourceUtils.dataSource(jdbcConfig);\n} catch (JdbcConnectorException e) {\n    if (e.getErrorCode() == CommonErrorCodeDeprecated.REFLECT_CLASS_OPERATION_FAILED) {\n        LOG.error(\"Driver class {} cannot be instantiated; check classpath/driver version\", jdbcConfig.getXaDataSourceClassName(), e.getCause());\n    }\n    throw e;\n}","preventionTips":["Ship the full driver jar in the SeaTunnel plugin/lib dir before submitting the job","Verify the XADataSource class name against your exact driver version docs","Smoke-test driver construction with a tiny local Java snippet mirroring the classloader setup","Pin driver versions and re-verify class names on upgrades"],"tags":["jdbc","reflection","xa-datasource","classpath"],"backgroundTag":"class-not-found","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}