brettwooldridge/HikariCP · error · RuntimeException
JNDI context does not found for dataSourceJNDI : ${jndiName}
Error message
JNDI context does not found for dataSourceJNDI : ${jndiName} What it means
HikariJNDIFactory (used to create pools from JNDI-bound properties) throws RuntimeException when dataSourceJNDI is configured but the passed-in JNDI Context is null, so the lookup cannot even be attempted. This is a factory wiring error, not a missing name error.
Source
Thrown at src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java:69
return createDataSource(properties, nameCtx);
}
return null;
}
private DataSource createDataSource(final Properties properties, final Context context) throws NamingException
{
var jndiName = properties.getProperty("dataSourceJNDI");
if (jndiName != null) {
return lookupJndiDataSource(properties, context, jndiName);
}
return new HikariDataSource(new HikariConfig(properties));
}
private DataSource lookupJndiDataSource(final Properties properties, final Context context, final String jndiName) throws NamingException
{
if (context == null) {
throw new RuntimeException("JNDI context does not found for dataSourceJNDI : " + jndiName);
}
var jndiDS = (DataSource) context.lookup(jndiName);
if (jndiDS == null) {
final var ic = new InitialContext();
jndiDS = (DataSource) ic.lookup(jndiName);
ic.close();
}
if (jndiDS != null) {
var config = new HikariConfig(properties);
config.setDataSource(jndiDS);
return new HikariDataSource(config);
}
return null;
}
}View on GitHub (pinned to a4d93f4f85)
Solutions
- Verify the container's JNDI Resource definition and that lookup happens inside a container-managed context
- Ensure the web.xml resource-ref and context.xml Resource entries match the dataSourceJNDI name
- If running outside a container, remove dataSourceJNDI and configure jdbcUrl/driver directly instead of a JNDI lookup
- In tests, provide an InitialContextFactory (e.g. simple-jndi) or mock the Context
Example fix
// before (context.xml Resource params include dataSourceJndiName but context lookup context is null)
<Parameter name="dataSourceJNDI" value="java:comp/env/jdbc/mydb" />
// after: define the Resource properly so the container supplies a non-null Context
<Resource name="jdbc/mydb" auth="Container"
factory="com.zaxxer.hikari.HikariJNDIFactory"
type="javax.sql.DataSource" ... /> Defensive patterns
Strategy: validation
Validate before calling
Context ctx = null;
try { ctx = new InitialContext(); }
catch (NamingException e) { /* container JNDI missing: do not use dataSourceJNDI config */ } Try / catch
try { ds = (DataSource) new HikariJNDIFactory().getObjectInstance(...); }
catch (RuntimeException e) {
if (e.getMessage().contains("JNDI context does not found")) { /* fix Resource config or drop JNDI */ }
throw e;
} Prevention
- Declare JNDI Resources correctly in context.xml/web.xml
- In non-container environments use jdbcUrl config instead of dataSourceJNDI
- Provide an InitialContextFactory in tests
When it happens
Trigger: Tomcat/JNDI resource factory invoked without a valid java:comp/env context; deploying in a container that never constructed the InitialContext; dataSourceJNDI property present in the Resource params while the factory receives a null Context (e.g. unit tests calling the factory directly).
Common situations: Migrating an app between servlet containers, missing <Resource> / resource-ref configuration, standalone tests exercising HikariJNDIFactory without a JNDI provider.
Related errors
- connectionTimeout cannot be less than ${SOFT_TIMEOUT_FLOOR}m
- idleTimeout cannot be negative
- maxPoolSize cannot be less than 1
- minimumIdle cannot be negative
- validationTimeout cannot be less than ${SOFT_TIMEOUT_FLOOR}m
AI-assisted analysis of brettwooldridge/HikariCP@a4d93f4f85 (2026-08-14).
Data as JSON: /api/errors/023d7d95412d8af6.
Report an issue: GitHub.