quarkusio/quarkus · error · RuntimeException
Failed to disable JNDI
Error message
Failed to disable JNDI
What it means
DisabledInitialContextManager.register() installs a JVM-wide InitialContextFactoryBuilder via NamingManager.setInitialContextFactoryBuilder to disable JNDI. If the JVM already has a builder set, or the setter rejects the registration, the resulting NamingException is wrapped in a RuntimeException("Failed to disable JNDI"). This is a startup-time failure, not an application-level naming failure.
Source
Thrown at independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/naming/DisabledInitialContextManager.java:26
import javax.naming.spi.InitialContextFactoryBuilder;
import javax.naming.spi.NamingManager;
/**
* Delegate used by Quarkus to disable JNDI.
* <p>
* This must be in a parent-first artifact as the initial context manager
* {@link NamingManager#setInitialContextFactoryBuilder(InitialContextFactoryBuilder) cannot be replaced}
* and will never get garbage-collected due to being referenced from a sticky class ({@link NamingManager}),
* so its classloader will never get garbage-collected either.
*/
public class DisabledInitialContextManager implements InitialContextFactoryBuilder {
public static synchronized void register() {
if (!NamingManager.hasInitialContextFactoryBuilder()) {
try {
NamingManager.setInitialContextFactoryBuilder(new DisabledInitialContextManager());
} catch (NamingException e) {
throw new RuntimeException("Failed to disable JNDI", e);
}
}
}
@Override
public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) throws NamingException {
return new InitialContextFactory() {
@Override
public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
return new DisabledInitialContext();
}
};
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Ensure register() is called only once per JVM and before any other framework installs an InitialContextFactoryBuilder.
- Check for other libraries/tests calling NamingManager.setInitialContextFactoryBuilder and remove the conflict.
- If embedding Quarkus, initialize Quarkus bootstrap before installing your own naming factory builder.
Example fix
// before
DisabledInitialContextManager.register(); // may throw if a builder already exists
// after
if (!NamingManager.hasInitialContextFactoryBuilder()) {
DisabledInitialContextManager.register();
} Defensive patterns
Strategy: try-catch
Validate before calling
if (NamingManager.hasInitialContextFactoryBuilder()) { /* another builder already installed; skip register() */ } Try / catch
try {
DisabledInitialContextManager.register();
} catch (RuntimeException e) {
if (e.getMessage().equals("Failed to disable JNDI")) {
log.warn("Another InitialContextFactoryBuilder already installed; JNDI not disabled", e);
} else throw e;
} Prevention
- Call register() exactly once, early in bootstrap.
- Check for other frameworks installing InitialContextFactoryBuilder in the same JVM.
- Serialize bootstrap initialization to avoid races on the JVM-wide naming manager.
When it happens
Trigger: Calling DisabledInitialContextManager.register() when NamingManager.setInitialContextFactoryBuilder throws NamingException — typically because another InitialContextFactoryBuilder was already installed earlier in the JVM (register() guards with hasInitialContextFactoryBuilder(), but a race or a previously installed builder from another component can still cause the setter to throw IllegalStateException/NamingException).
Common situations: Two Quarkus bootstrap components both trying to disable JNDI in the same JVM, or another framework (app server, test harness) having installed its own InitialContextFactoryBuilder before Quarkus bootstrap runs.
Related errors
- configuration id '<key>' duplicates the default configuratio
- ${methodName} is not a getter
- Failed to start Quarkus
- Quarkus failed to start up
- Unable to find top command. Ensure you have a @CommandDefini
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/96f1e4b44cf62d56.
Report an issue: GitHub.