{"record":{"id":"71c6a1dd8e45374b","repo":"pentaho/pentaho-kettle","slug":"error-initializing-jndi","errorCode":null,"errorMessage":"Error initializing JNDI","messagePattern":"Error initializing JNDI","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/JndiUtil.java","lineNumber":31,"sourceCode":"\n\npackage org.pentaho.di.core;\n\nimport java.io.File;\n\nimport org.pentaho.di.core.exception.KettleException;\n\npublic class JndiUtil {\n\n  public static void initJNDI() throws KettleException {\n    String path = Const.JNDI_DIRECTORY;\n\n    if ( path == null || path.equals( \"\" ) ) {\n      try {\n        File file = new File( \"simple-jndi\" );\n        path = file.getCanonicalPath();\n      } catch ( Exception e ) {\n        throw new KettleException( \"Error initializing JNDI\", e );\n      }\n      Const.JNDI_DIRECTORY = path;\n    }\n\n    System.setProperty( \"java.naming.factory.initial\", \"org.osjava.sj.SimpleContextFactory\" );\n    System.setProperty( \"org.osjava.sj.root\", path );\n    System.setProperty( \"org.osjava.sj.delimiter\", \"/\" );\n  }\n\n}\n","sourceCodeStart":13,"sourceCodeEnd":42,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/JndiUtil.java#L13-L42","documentation":"initJNDI throws KettleException when it cannot determine the JNDI root directory: the given path is empty and resolving the relative path 'simple-jndi' via File.getCanonicalPath() fails (IOException). This initialization is required before looking up datasources via JNDI.","triggerScenarios":"Calling JndiUtil.initJNDI() with a null/empty path while the process working directory is unreadable/deleted, or getCanonicalPath() throws due to an I/O error resolving 'simple-jndi'.","commonSituations":"Running a transformation from a deleted or permission-restricted working directory, embedding Pentaho in an app server where CWD is not the PDI root so 'simple-jndi' cannot be resolved, containerizing Kettle without setting KETTLE_JNDI_DIRECTORY / Const.JNDI_DIRECTORY.","solutions":["Pass an explicit, existing directory path to initJNDI instead of relying on the default 'simple-jndi' relative path","Ensure the process working directory contains the simple-jndi directory and is readable","Set the JNDI directory system/environment configuration (Const.JNDI_DIRECTORY) before initialization","Verify file permissions on the working directory (chmod) or launch from a valid directory"],"exampleFix":"// before\nJndiUtil.initJNDI(\"\");\n// after\nJndiUtil.initJNDI(\"/opt/pentaho/simple-jndi\");","handlingStrategy":"validation","validationCode":"File jndiDir = new File(jndiPath == null || jndiPath.isEmpty() ? \"simple-jndi\" : jndiPath);\nif (!jndiDir.exists() || !jndiDir.canRead()) {\n  throw new IllegalStateException(\"JNDI directory missing or unreadable: \" + jndiDir.getAbsolutePath());\n}","typeGuard":null,"tryCatchPattern":"try {\n  JndiUtil.initJNDI(path);\n} catch (KettleException e) {\n  throw new IllegalStateException(\"JNDI init failed; check working dir / simple-jndi folder\", e);\n}","preventionTips":["Always set an absolute JNDI directory in embedded/container deployments","Ensure the process working directory contains simple-jndi and is readable","Call JNDI initialization once during bootstrap before any datasource lookups"],"tags":["jndi","configuration","io","initialization"],"backgroundTag":"module-init-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"}