{"id":"b41fa0b933cb4ca4","repo":"apache/kafka","slug":"path-is-not-supported-for-envvarconfigprovider-in","errorCode":null,"errorMessage":"Path is not supported for EnvVarConfigProvider, invalid value '{path}'","messagePattern":"Path is not supported for EnvVarConfigProvider, invalid value '(.+?)'","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/provider/EnvVarConfigProvider.java","lineNumber":100,"sourceCode":"     * @param path unused\n     * @return returns environment variables as configuration\n     */\n    @Override\n    public ConfigData get(String path) {\n        return get(path, null);\n    }\n\n    /**\n     * @param path    path, not used for environment variables\n     * @param keys the keys whose values will be retrieved.\n     * @return the configuration data.\n     */\n    @Override\n    public ConfigData get(String path, Set<String> keys) {\n\n        if (path != null && !path.isEmpty()) {\n            log.error(\"Path is not supported for EnvVarConfigProvider, invalid value '{}'\", path);\n            throw new ConfigException(\"Path is not supported for EnvVarConfigProvider, invalid value '\" + path + \"'\");\n        }\n\n        if (keys == null) {\n            return new ConfigData(filteredEnvVarMap);\n        }\n\n        Map<String, String> filteredData = new HashMap<>(filteredEnvVarMap);\n        filteredData.keySet().retainAll(keys);\n\n        return new ConfigData(filteredData);\n    }\n\n    private Map<String, String> getEnvVars() {\n        try {\n            return System.getenv();\n        } catch (Exception e) {\n            log.error(\"Could not read environment variables\", e);\n            throw new ConfigException(\"Could not read environment variables\");","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/provider/EnvVarConfigProvider.java#L82-L118","documentation":"Thrown as ConfigException by EnvVarConfigProvider.get(path, keys) when a non-null, non-empty path is supplied. The provider sources values from System.getenv() only; the path parameter is explicitly documented as unused, so any value is treated as a misconfiguration and rejected. Keys are matched against the configured allowlist pattern instead.","triggerScenarios":"Externalized config substitution referencing the env provider with a path segment, e.g. ${env:/path/to:KEY} or ${env:someDir:VAR}, which calls EnvVarConfigProvider.get(\"/path/to\", keys) with a non-empty path. Any direct call get(nonEmptyPath, keys) on the env provider.","commonSituations":"Confusing EnvVarConfigProvider with FileConfigProvider/DirectoryConfigProvider and supplying a path placeholder in the config substitution syntax. Copying a ${file:/etc/secrets:...} pattern and forgetting to drop the path when switching to ${env:...}.","solutions":["Remove the path segment from the substitution: use ${env:VAR_NAME} (or ${env::VAR_NAME}) instead of ${env:/some/path:VAR_NAME}.","Confirm the provider name maps to EnvVarConfigProvider and switch to FileConfigProvider/DirectoryConfigProvider if you actually need filesystem lookups.","If calling get() directly, pass null or empty string as the path argument."],"exampleFix":"# before\nconfig.providers=env\nvalue=${env:/etc/secrets:API_KEY}\n\n# after\nconfig.providers=env\nvalue=${env:API_KEY}","handlingStrategy":"validation","validationCode":"// EnvVarConfigProvider ignores path; never pass a meaningful value.\nString safePath = (path == null || path.isEmpty()) ? null : null;\n// i.e. force null/empty before calling get():\nConfigData data = envProvider.get(null);","typeGuard":null,"tryCatchPattern":"try {\n    envProvider.get(path);\n} catch (ConfigException e) {\n    if (e.getMessage() != null\n            && e.getMessage().contains(\"Path is not supported for EnvVarConfigProvider\")) {\n        envProvider.get(null); // retry with no path\n    } else { throw e; }\n}","preventionTips":["EnvVarConfigProvider.get(path) does not use path — always pass null or empty string.","If a generic ConfigProvider pipeline supplies path, special-case EnvVarConfigProvider to coerce path to null.","Document/abstract this in a shared helper so callers cannot accidentally feed a path to an env-var-only provider."],"tags":["config-provider","env-config-provider","externalized-config","config-substitution"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}