{"record":{"id":"6cff8c5930446869","repo":"alibaba/druid","slug":"create-driver-instance-error-driver-classname","errorCode":null,"errorMessage":"create driver instance error, driver className '","messagePattern":"create driver instance error, driver className '","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/proxy/DruidDriver.java","lineNumber":265,"sourceCode":"        }\n        config.setUrl(url);\n        return config;\n    }\n\n    public static Driver createDriver(final String className) throws SQLException {\n        Class<?> rawDriverClass = Utils.loadClass(className);\n\n        if (rawDriverClass == null) {\n            throw new SQLException(\"jdbc-driver's class not found. '\" + className + \"'\");\n        }\n\n        Driver rawDriver;\n        try {\n            rawDriver = (Driver) rawDriverClass.newInstance();\n        } catch (InstantiationException e) {\n            throw new SQLException(\"create driver instance error, driver className '\" + className + \"'\", e);\n        } catch (IllegalAccessException e) {\n            throw new SQLException(\"create driver instance error, driver className '\" + className + \"'\", e);\n        }\n\n        return rawDriver;\n    }\n\n    @Override\n    public int getMajorVersion() {\n        return this.majorVersion;\n    }\n\n    @Override\n    public int getMinorVersion() {\n        return this.minorVersion;\n    }\n\n    @Override\n    public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {\n        DataSourceProxyImpl dataSource = getDataSource(url, info);","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/proxy/DruidDriver.java#L247-L283","documentation":"DruidDriver.createDriver(className) catches IllegalAccessException when calling rawDriverClass.newInstance() — the driver class loaded, but its no-arg constructor (or the class itself) is not accessible from Druid's classloader. The chained IllegalAccessException explains which access failed. This is the same createDriver path as the InstantiationException variant; both indicate the named class cannot be instantiated reflectively.","triggerScenarios":"rawDriverClassName points at a class with a non-public constructor or a non-public class; or the classloader that loaded Druid cannot access the driver's constructor due to Java module/access restrictions (e.g. setAccessible refused on JDK 9+ without --add-opens).","commonSituations":"Driver shaded/relocated by a tool that changed visibility; module-path (JPMS) deployment restricting reflective access; custom driver subclass with a package-private constructor; security manager denying access.","solutions":["Use the standard, public, unmodified driver class shipped by the vendor so its constructor is accessible.","If on JPMS, ensure open packages or add the required --add-opens JVM flag for the driver module.","Inspect the chained IllegalAccessException to identify the inaccessible member, then widen access or switch to a DataSource-based config that constructs the driver directly."],"exampleFix":"// before\n// rawDriverClassName points at a relocated/shaded driver with package-private ctor\nDriverManager.getConnection(\"jdbc:wrap-druid://...\"); // throws 'create driver instance error'\n\n// after\n// use the canonical public driver class:\n// rawDriverClassName = com.mysql.cj.jdbc.Driver\n// or switch to DataSource config and instantiate the driver directly in code.","handlingStrategy":"validation","validationCode":"Class<?> c = Utils.loadClass(className);\nif (c != null) {\n    int mod = c.getModifiers();\n    if (!Modifier.isPublic(mod)) {\n        throw new IllegalStateException(className + \" class is not public\");\n    }\n    try {\n        java.lang.reflect.Constructor<?> ctor = c.getDeclaredConstructor();\n        if (!Modifier.isPublic(ctor.getModifiers())) {\n            throw new IllegalStateException(className + \" no-arg constructor is not public\");\n        }\n    } catch (NoSuchMethodException e) {\n        throw new IllegalStateException(className + \" has no no-arg constructor\", e);\n    }\n}","typeGuard":"public static boolean publiclyInstantiableDriver(String className) {\n    Class<?> c = Utils.loadClass(className);\n    if (c == null || !Modifier.isPublic(c.getModifiers())) return false;\n    try {\n        return Modifier.isPublic(c.getDeclaredConstructor().getModifiers());\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    Driver d = DruidDriver.createDriver(className);\n} catch (SQLException e) {\n    if (e.getCause() instanceof IllegalAccessException) {\n        throw new IllegalStateException(\"driver class/constructor not accessible: \" + className\n            + \" (check JPMS --add-opens or use the stock driver class)\", e);\n    }\n    throw e;\n}","preventionTips":["Use the vendor's unmodified, public driver class; avoid relocated/shaded variants that change visibility.","On JPMS, add the necessary --add-opens for the driver module.","Prefer DataSource-based configuration over the proxy driver when access is restricted."],"tags":["driver-loading","access-control","reflective-access","configuration"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}