{"id":"97c994fd655db328","repo":"junit-team/junit5","slug":"the-charset-supplied-in-csvfilesource-is-invali","errorCode":null,"errorMessage":"The charset supplied in ${csvFileSource} 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/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/CsvFileArgumentsProvider.java#L59-L95","documentation":"CsvFileArgumentsProvider.getCharsetFrom calls Charset.forName with the @CsvFileSource.encoding attribute and wraps any failure as a PreconditionViolationException. The supplied encoding string is not a charset name or alias recognized by the JVM.","triggerScenarios":"Setting @CsvFileSource(encoding = \"...\") to a value Charset.forName rejects - a typo, a non-registered alias, or an unsupported IANA name on a stripped JRE.","commonSituations":"Typo such as 'UTF-8 ' (trailing space) or 'UTS-8'; using an IANA name not aliased on the runtime; custom charset provider missing on a minimal JRE.","solutions":["Use a canonical charset name (e.g. UTF-8, ISO-8859-1, US-ASCII).","Omit the encoding attribute entirely to fall back to the default (UTF-8).","Verify availability up front via Charset.availableCharsets()."],"exampleFix":"// before\n@CsvFileSource(resources = \"/data.csv\", encoding = \"UTF8-BOM\")\n\n// after\n@CsvFileSource(resources = \"/data.csv\", encoding = \"UTF-8\")","handlingStrategy":"validation","validationCode":"// Verify the encoding name resolves before using @CsvFileSource.\nString encoding = \"UTF-8\";\ntry {\n    Charset.forName(encoding);\n} catch (IllegalArgumentException ex) {\n    throw new IllegalArgumentException(\"Invalid @CsvFileSource encoding: \" + encoding, ex);\n}","typeGuard":null,"tryCatchPattern":"try {\n    // run the CSV-file parameterized test\n} catch (PreconditionViolationException e) {\n    if (e.getMessage().contains(\"charset supplied in\")) {\n        // switch to a canonical charset name (UTF-8) or drop the encoding attribute\n    } else throw e;\n}","preventionTips":["Use names from java.nio.charset.StandardCharsets.","Prefer omitting encoding to accept the UTF-8 default.","Validate the name via Charset.availableCharsets() when it must be configurable."],"tags":["junit","jupiter-params","csv","charset","configuration"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}