{"record":{"id":"45b7c96d6a183efb","repo":"junit-team/junit5","slug":"the-charset-supplied-in-s-is-invalid","errorCode":null,"errorMessage":"The charset supplied in %s is invalid","messagePattern":"The charset supplied in (.+?) is invalid","errorType":"exception","errorClass":"PreconditionViolationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java","lineNumber":77,"sourceCode":"\t\tStream<Source> resources = Arrays.stream(csvFileSource.resources()).map(inputStreamProvider::classpathResource);\n\t\tStream<Source> files = Arrays.stream(csvFileSource.files()).map(inputStreamProvider::file);\n\t\tList<Source> sources = Stream.concat(resources, files).toList();\n\n\t\t// @formatter:off\n\t\treturn Preconditions.notEmpty(sources, \"Resources or files must not be empty\")\n\t\t\t\t.stream()\n\t\t\t\t.map(source -> source.open(context))\n\t\t\t\t.map(inputStream -> CsvReaderFactory.createReaderFor(configuration, inputStream, charset))\n\t\t\t\t.flatMap(reader -> toStream(reader, csvFileSource));\n\t\t// @formatter:on\n\t}\n\n\tprivate static Charset getCharsetFrom(CsvFileSource csvFileSource) {\n\t\ttry {\n\t\t\treturn Charset.forName(csvFileSource.encoding());\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new PreconditionViolationException(\"The charset supplied in \" + csvFileSource + \" is invalid\", ex);\n\t\t}\n\t}\n\n\tprivate static Stream<Arguments> toStream(CsvReader<? extends CsvRecord> reader, CsvFileSource csvFileSource) {\n\t\tvar spliterator = CsvExceptionHandlingSpliterator.delegatingTo(reader.spliterator(), csvFileSource);\n\t\tboolean useHeadersInDisplayName = csvFileSource.useHeadersInDisplayName();\n\t\t// @formatter:off\n\t\treturn StreamSupport.stream(spliterator, false)\n\t\t\t\t.skip(csvFileSource.numLinesToSkip())\n\t\t\t\t.map(record -> CsvArgumentsProvider.processCsvRecord(\n\t\t\t\t\t\trecord, useHeadersInDisplayName)\n\t\t\t\t)\n\t\t\t\t.onClose(() -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\treader.close();\n\t\t\t\t\t}\n\t\t\t\t\tcatch (Throwable throwable) {\n\t\t\t\t\t\tthrow CsvArgumentsProvider.handleCsvException(throwable, csvFileSource);","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java#L59-L95","documentation":"Thrown by CsvFileArgumentsProvider.getCharsetFrom when Charset.forName rejects the encoding name supplied in @CsvFileSource(encoding = ...). The message includes the @CsvFileSource annotation so the offending config is identifiable. The cause is the underlying UnsupportedCharsetException or IllegalCharsetNameException.","triggerScenarios":"Setting @CsvFileSource(encoding = \"XYZ\") where XYZ is not a valid/registered charset name in the JVM. Typo in a charset name, or referencing a charset not available in the runtime.","commonSituations":"Misspelled charset such as \"UTF8\" instead of \"UTF-8\", or \"utf-8\" with stray characters. Running on a JVM without the requested charset provider. Copy-paste from a system that used a non-IANA alias.","solutions":["Use a canonical charset name such as UTF-8, ISO-8859-1, US-ASCII.","Remove the encoding attribute to use the default charset if the file is in the platform default.","Verify the charset is available: Charset.availableCharsets().containsKey(name)."],"exampleFix":"// before\n@CsvFileSource(resources = \"/data.csv\", encoding = \"UTF8\")\n\n// after\n@CsvFileSource(resources = \"/data.csv\", encoding = \"UTF-8\")","handlingStrategy":"validation","validationCode":"// Validate the charset name before the test runs\nString encoding = \"UTF-8\";\nif (!Charset.availableCharsets().containsKey(encoding))\n    throw new IllegalArgumentException(\"Unsupported charset: \" + encoding);","typeGuard":"static boolean isValidCharset(String name) {\n    try { Charset.forName(name); return true; } catch (Exception e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Use canonical charset names (UTF-8, ISO-8859-1, US-ASCII).","Omit the encoding attribute when the platform default is acceptable.","Centralize charset constants to avoid typos."],"tags":["junit-jupiter","csv","charset","configuration"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}