{"record":{"id":"96f1e4b44cf62d56","repo":"quarkusio/quarkus","slug":"failed-to-disable-jndi","errorCode":null,"errorMessage":"Failed to disable JNDI","messagePattern":"Failed to disable JNDI","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/naming/DisabledInitialContextManager.java","lineNumber":26,"sourceCode":"import javax.naming.spi.InitialContextFactoryBuilder;\nimport javax.naming.spi.NamingManager;\n\n/**\n * Delegate used by Quarkus to disable JNDI.\n * <p>\n * This must be in a parent-first artifact as the initial context manager\n * {@link NamingManager#setInitialContextFactoryBuilder(InitialContextFactoryBuilder) cannot be replaced}\n * and will never get garbage-collected due to being referenced from a sticky class ({@link NamingManager}),\n * so its classloader will never get garbage-collected either.\n */\npublic class DisabledInitialContextManager implements InitialContextFactoryBuilder {\n\n    public static synchronized void register() {\n        if (!NamingManager.hasInitialContextFactoryBuilder()) {\n            try {\n                NamingManager.setInitialContextFactoryBuilder(new DisabledInitialContextManager());\n            } catch (NamingException e) {\n                throw new RuntimeException(\"Failed to disable JNDI\", e);\n            }\n        }\n    }\n\n    @Override\n    public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) throws NamingException {\n        return new InitialContextFactory() {\n            @Override\n            public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {\n                return new DisabledInitialContext();\n            }\n        };\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":41,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/naming/DisabledInitialContextManager.java#L8-L41","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nDisabledInitialContextManager.register(); // may throw if a builder already exists\n\n// after\nif (!NamingManager.hasInitialContextFactoryBuilder()) {\n    DisabledInitialContextManager.register();\n}","handlingStrategy":"try-catch","validationCode":"if (NamingManager.hasInitialContextFactoryBuilder()) { /* another builder already installed; skip register() */ }","typeGuard":null,"tryCatchPattern":"try {\n    DisabledInitialContextManager.register();\n} catch (RuntimeException e) {\n    if (e.getMessage().equals(\"Failed to disable JNDI\")) {\n        log.warn(\"Another InitialContextFactoryBuilder already installed; JNDI not disabled\", e);\n    } else throw e;\n}","preventionTips":["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."],"tags":["jndi","naming","startup"],"backgroundTag":"jndi-disabled","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}