{"record":{"id":"2fb32aa27b84d0d4","repo":"junit-team/junit5","slug":"localeprovider-instance-returned-with-null","errorCode":null,"errorMessage":"LocaleProvider instance returned with null","messagePattern":"LocaleProvider instance returned with null","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java","lineNumber":122,"sourceCode":"\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"@DefaultLocale can only be used with a provider if value, language, country and variant are not set.\");\n\t\tvar providerClass = annotation.localeProvider();\n\t\tLocaleProvider provider;\n\t\ttry {\n\t\t\tprovider = ReflectionSupport.newInstance(providerClass);\n\t\t}\n\t\tcatch (Exception exception) {\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"LocaleProvider instance could not be constructed because of an exception\", exception);\n\t\t}\n\t\treturn invoke(provider);\n\t}\n\n\t@SuppressWarnings(\"ConstantValue\")\n\tprivate static Locale invoke(LocaleProvider provider) {\n\t\tvar locale = provider.get();\n\t\tif (locale == null) {\n\t\t\tthrow new ExtensionConfigurationException(\"LocaleProvider instance returned with null\");\n\t\t}\n\t\treturn locale;\n\t}\n\n\t@Override\n\tpublic void afterEach(ExtensionContext context) {\n\t\tload(context, DEFAULT_KEY).ifPresent(Locale::setDefault);\n\t}\n\n\tprivate static void store(ExtensionContext context, String key, Locale value) {\n\t\tgetStore(context).put(key, value);\n\t}\n\n\tprivate static Optional<Locale> load(ExtensionContext context, String key) {\n\t\treturn Optional.ofNullable(getStore(context).get(key, Locale.class));\n\t}\n\n\tprivate static ExtensionContext.Store getStore(ExtensionContext context) {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L104-L140","documentation":"ExtensionConfigurationException from DefaultLocaleExtension.invoke, thrown when the configured LocaleProvider.get() returns null. A provider must return a non-null Locale; null is treated as a configuration defect rather than a meaningful value.","triggerScenarios":"Specifying @DefaultLocale(localeProvider = MyProvider.class) where MyProvider.get() returns null — e.g. a lookup that yielded no result and returned null instead of a default.","commonSituations":"Provider that reads Locale from an env var or system property that is unset; a provider that returns null 'to mean default'; copy of a stub provider that was never finished.","solutions":["Make get() return a concrete Locale (e.g. Locale.getDefault() or Locale.ROOT) instead of null.","Guard the lookup inside get(): Optional.ofNullable(...).orElse(Locale.ROOT)."],"exampleFix":"// before\npublic Locale get() { return readFromEnv(); } // returns null when unset\n// after\npublic Locale get() {\n    return Optional.ofNullable(readFromEnv()).orElse(Locale.ROOT);\n}","handlingStrategy":"validation","validationCode":"Locale l = provider.get();\nif (l == null) throw new IllegalStateException(\"provider returned null\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["LocaleProvider.get() must never return null.","Fallback to Locale.ROOT or Locale.getDefault() inside get().","Unit-test the provider independently before wiring it into the extension."],"tags":["default-locale","locale-provider","null-return","extension-config"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}