{"record":{"id":"25c640739127ee75","repo":"pentaho/pentaho-kettle","slug":"databaseutil-dsnotfound","errorCode":"DatabaseUtil.DSNotFound","errorMessage":"DatabaseUtil.DSNotFound (localized, parameter: dsName)","messagePattern":"DatabaseUtil\\.DSNotFound \\(localized, parameter: dsName\\)","errorType":"exception","errorClass":"NamingException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/util/DatabaseUtil.java","lineNumber":63,"sourceCode":"\n  /**\n   * Clears cache of DataSources (For Unit test)\n   */\n  protected static void clearDSCache() {\n    FoundDS.clear();\n  }\n\n  /**\n   * Since JNDI is supported different ways in different app servers, it's nearly impossible to have a ubiquitous way to\n   * look up a datasource. This method is intended to hide all the lookups that may be required to find a jndi name.\n   *\n   * @param dsName The Datasource name\n   * @return DataSource if there is one bound in JNDI\n   * @throws NamingException\n   */\n  protected static DataSource getDataSourceFromJndi( String dsName, Context ctx ) throws NamingException {\n    if ( Utils.isEmpty( dsName ) ) {\n      throw new NamingException( BaseMessages.getString( PKG, \"DatabaseUtil.DSNotFound\", String.valueOf( dsName ) ) );\n    }\n    Object foundDs = FoundDS.get( dsName );\n    if ( foundDs != null ) {\n      return (DataSource) foundDs;\n    }\n    Object lkup = null;\n    DataSource rtn = null;\n    NamingException firstNe = null;\n    // First, try what they ask for...\n    try {\n      lkup = ctx.lookup( dsName );\n      if ( lkup instanceof DataSource ) {\n        rtn = (DataSource) lkup;\n        FoundDS.put( dsName, rtn );\n        return rtn;\n      }\n    } catch ( NamingException ignored ) {\n      firstNe = ignored;","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/util/DatabaseUtil.java#L45-L81","documentation":"DatabaseUtil.getDataSourceFromJndi throws a NamingException when the requested datasource name is empty, with a localized message keyed DatabaseUtil.DSNotFound that includes the dsName. This is a fast-fail guard before any JNDI lookup is attempted.","triggerScenarios":"Calling getDataSourceFromJndi with a null or empty-string dsName (Utils.isEmpty check) while resolving a JNDI datasource against the given Context.","commonSituations":"Empty JNDI name in database connection metadata (e.g. a database connection saved without a datasource name), environment variables or properties that resolve to blank, or refactored code passing an unset variable.","solutions":["Provide a valid non-empty JNDI datasource name before calling the lookup.","Check the database connection settings in Spoon/repository and set the JNDI name.","Validate the configuration value that feeds dsName (property/env variable may be empty).","Catch NamingException and surface a clear message naming the missing datasource."],"exampleFix":"// before\nDataSource ds = DatabaseUtil.getDataSourceFromJndi( cfg.getJndiName(), ctx ); // jndiName == \"\"\n// after\nif ( Utils.isEmpty( cfg.getJndiName() ) ) {\n  throw new IllegalArgumentException( \"JNDI datasource name must be set\" );\n}\nDataSource ds = DatabaseUtil.getDataSourceFromJndi( cfg.getJndiName(), ctx );","handlingStrategy":"validation","validationCode":"if ( dsName == null || dsName.trim().isEmpty() ) {\n  throw new IllegalArgumentException( \"JNDI datasource name must be provided\" );\n}\n// then call DatabaseUtil.getDataSourceFromJndi(dsName, ctx)","typeGuard":"boolean hasJndiName( String s ) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try {\n  ds = DatabaseUtil.getDataSourceFromJndi( dsName, ctx );\n} catch ( NamingException e ) {\n  if ( dsName == null || dsName.isEmpty() ) {\n    throw new IllegalStateException( \"Datasource name is empty; fix connection config\", e );\n  }\n  throw e;\n}","preventionTips":["Validate datasource name at configuration load time","Never pass raw env/property values without empty checks","Set JNDI names in connection metadata via UI/repository, not ad hoc strings"],"tags":["jndi","datasource","empty-name"],"backgroundTag":"missing-required-argument","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"}