{"record":{"id":"7b03010c656379b2","repo":"pentaho/pentaho-kettle","slug":"exception-while-loading-class","errorCode":null,"errorMessage":"Exception while loading class","messagePattern":"Exception while loading class","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":657,"sourceCode":"\n  private void loadStaticDriver( String classname, PluginInterface plugin ) throws KettleDatabaseException {\n    try {\n      synchronized ( java.sql.DriverManager.class ) {\n        ClassLoader classLoader = PluginRegistry.getInstance().getClassLoader( plugin );\n        Class<?> driverClass = classLoader.loadClass( classname );\n        // Only need DelegatingDriver for drivers not from our classloader\n        if ( driverClass.getClassLoader() != this.getClass().getClassLoader() ) {\n          registerDelegatingDriver( driverClass );\n        } else {\n          // Trigger static register block in driver class\n          Class.forName( classname );\n        }\n      }\n    } catch ( NoClassDefFoundError | ClassNotFoundException e ) {\n      throw new KettleDatabaseException( BaseMessages.getString( PKG,\n        \"Database.Exception.UnableToFindClassMissingDriver\", classname, plugin.getName() ), e );\n    } catch ( Exception e ) {\n      throw new KettleDatabaseException( \"Exception while loading class\", e );\n    }\n  }\n\n  private void registerDelegatingDriver( Class<?> driverClass ) throws KettleDatabaseException {\n    String pluginId =\n      PluginRegistry.getInstance().getPluginId( DatabasePluginType.class, databaseMeta.getDatabaseInterface() );\n    Set<String> registeredDriversFromPlugin = registeredDrivers.computeIfAbsent( pluginId, k -> new HashSet<>() );\n    // Prevent registering multiple delegating drivers for same class, plugin\n    if ( !registeredDriversFromPlugin.contains( driverClass.getCanonicalName() ) ) {\n      try {\n        DriverManager.registerDriver( new DelegatingDriver( (Driver) driverClass.getDeclaredConstructor().newInstance() ) );\n      } catch ( InstantiationException | IllegalAccessException | NoSuchMethodException | java.lang.reflect.InvocationTargetException | SQLException e ) {\n        throw new KettleDatabaseException(\n          \"Unable to register delegating driver for class \" + driverClass.getCanonicalName(), e );\n      }\n      registeredDriversFromPlugin.add( driverClass.getCanonicalName() );\n    }\n  }","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L639-L675","documentation":"loadStaticDriver's final catch (Exception) wraps any unexpected error during driver class loading/registration (other than ClassNotFoundException/NoClassDefFoundError) into KettleDatabaseException(\"Exception while loading class\"). Typically this is a linkage or initialization error inside the driver class's static initializer.","triggerScenarios":"ExceptionInInitializerError-like conditions or other RuntimeExceptions thrown when Class.forName triggers the driver's static registration block — corrupted jars, incompatible dependency versions, or static init that depends on missing system properties.","commonSituations":"Driver jar built for a different JVM/dependency version, partially downloaded/corrupted jar, conflicting versions of a shared dependency (e.g. protobuf vs newer drivers), security policy blocking class definition.","solutions":["Inspect the wrapped cause — ExceptionInInitializerError exposes the static-init failure via getCause()","Replace the driver jar with a fresh, compatible download","Resolve conflicting dependency versions on the classpath","Run with -verbose:class to confirm the class is loaded from the expected jar location"],"exampleFix":"// before\n// conflicting protobuf jars on classpath -> static init fails\nlib/protobuf-java-2.5.0.jar\nlib/protobuf-java-3.19.0.jar\n\n// after\nlib/protobuf-java-3.19.0.jar  // single version matching driver requirement","handlingStrategy":"try-catch","validationCode":"try {\n  Class.forName( driverClassname, true, loader );\n} catch ( Throwable t ) {\n  log.error( \"Driver failed static initialization: \" + t.getCause(), t );\n}","typeGuard":null,"tryCatchPattern":"try {\n  db.connect();\n} catch ( KettleDatabaseException e ) {\n  if ( \"Exception while loading class\".equals( e.getMessage() ) ) {\n    Throwable initFailure = e.getCause() != null ? e.getCause().getCause() : null;\n    log.error( \"Driver init problem: \" + initFailure, initFailure );\n  }\n}","preventionTips":["Deduplicate dependency versions that drivers rely on (e.g. protobuf, guava)","Verify jar integrity (checksums) after download/transfer","Load drivers once at startup to surface init errors early","Keep JVM version aligned with driver requirements"],"tags":["class-loading","driver","static-initializer"],"backgroundTag":"class-loading-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}