{"record":{"id":"2f8269df1a4ade53","repo":"mybatis/mybatis-3","slug":"failed-to-load-language-driver-for-cls-getname","errorCode":null,"errorMessage":"Failed to load language driver for \" + cls.getName()","messagePattern":"Failed to load language driver for \" \\+ cls\\.getName\\(\\)","errorType":"exception","errorClass":"ScriptingException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java","lineNumber":38,"sourceCode":"\n/**\n * @author Frank D. Martinez [mnesarco]\n */\npublic class LanguageDriverRegistry {\n\n  private final Map<Class<? extends LanguageDriver>, LanguageDriver> languageDriverMap = new HashMap<>();\n\n  private Class<? extends LanguageDriver> defaultDriverClass;\n\n  public void register(Class<? extends LanguageDriver> cls) {\n    if (cls == null) {\n      throw new IllegalArgumentException(\"null is not a valid Language Driver\");\n    }\n    languageDriverMap.computeIfAbsent(cls, k -> {\n      try {\n        return k.getDeclaredConstructor().newInstance();\n      } catch (Exception ex) {\n        throw new ScriptingException(\"Failed to load language driver for \" + cls.getName(), ex);\n      }\n    });\n  }\n\n  public void register(LanguageDriver instance) {\n    if (instance == null) {\n      throw new IllegalArgumentException(\"null is not a valid Language Driver\");\n    }\n    Class<? extends LanguageDriver> cls = instance.getClass();\n    if (!languageDriverMap.containsKey(cls)) {\n      languageDriverMap.put(cls, instance);\n    }\n  }\n\n  public LanguageDriver getDriver(Class<? extends LanguageDriver> cls) {\n    return languageDriverMap.get(cls);\n  }\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java#L20-L56","documentation":"When a LanguageDriver class is registered by Class, the registry instantiates it reflectively via its declared no-arg constructor. If construction fails — the class has no no-arg constructor, is abstract/interface, or the constructor throws — the exception is wrapped in a ScriptingException naming the driver class. The driver must be a concrete class with a usable public/accessible no-arg constructor.","triggerScenarios":"register(MyDriver.class) where MyDriver only has constructor MyDriver(String); registering an abstract driver base class; a driver whose no-arg constructor throws (missing dependency, failed init); non-public class under restrictive module/access rules.","commonSituations":"Custom scripting language drivers with parameterized constructors; drivers with initialization that requires config passed in; JPMS/strong-encapsulation environments blocking reflective access to the constructor.","solutions":["Add a public no-arg constructor to the driver class","Register a pre-built instance instead: registry.register(new MyDriver(deps)) — the instance overload skips instantiation","Ensure the class is concrete (not abstract/interface) and accessible for reflective instantiation","Check the wrapped cause for constructor-time failures (missing dependencies) and fix driver initialization"],"exampleFix":"// before\nclass MyDriver implements LanguageDriver {\n  MyDriver(Config c) { ... } // only constructor -> register(MyDriver.class) throws\n}\n\n// after\nregistry.register(new MyDriver(config)); // register the instance","handlingStrategy":"fallback","validationCode":"try {\n  cls.getDeclaredConstructor(); // proves a no-arg constructor exists\n  registry.register(cls);\n} catch (NoSuchMethodException e) {\n  registry.register(newInstanceSomehow(cls)); // register an instance instead\n}","typeGuard":null,"tryCatchPattern":"try {\n  registry.register(MyDriver.class);\n} catch (ScriptingException e) {\n  // fall back to instance registration if you can construct it\n  registry.register(new MyDriver(deps));\n}","preventionTips":["Give custom drivers a public no-arg constructor","Prefer registering pre-built instances when construction needs arguments","Test driver registration during application bootstrap, not on first query"],"tags":["configuration","language-driver","instantiation","mybatis"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}