{"record":{"id":"b68498eca95479ed","repo":"junit-team/junit5","slug":"failed-to-transform-configuration-parameter-with-k","errorCode":null,"errorMessage":"Failed to transform configuration parameter with key '%s' and initial value '%s'","messagePattern":"Failed to transform configuration parameter with key '(.+?)' and initial value '(.+?)'","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-engine/src/main/java/org/junit/platform/engine/ConfigurationParameters.java","lineNumber":129,"sourceCode":"\t * @return an {@code Optional} containing the value; never {@code null}\n\t * but potentially empty\n\t *\n\t * @since 1.3\n\t * @see #getBoolean(String)\n\t * @see System#getProperty(String)\n\t * @see #CONFIG_FILE_NAME\n\t */\n\t@API(status = STABLE, since = \"1.3\")\n\tdefault <T> Optional<T> get(String key, Function<? super String, ? extends @Nullable T> transformer) {\n\t\tPreconditions.notNull(transformer, \"transformer must not be null\");\n\t\treturn get(key).map(input -> {\n\t\t\ttry {\n\t\t\t\treturn transformer.apply(input);\n\t\t\t}\n\t\t\tcatch (Exception ex) {\n\t\t\t\tString message = \"Failed to transform configuration parameter with key '%s' and initial value '%s'\".formatted(\n\t\t\t\t\tkey, input);\n\t\t\t\tthrow new JUnitException(message, ex);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Get the keys of all configuration parameters stored in this\n\t * {@code ConfigurationParameters}.\n\t *\n\t * @return the set of keys contained in this {@code ConfigurationParameters}\n\t */\n\t@API(status = STABLE, since = \"1.9\")\n\tSet<String> keySet();\n\n}\n","sourceCodeStart":111,"sourceCodeEnd":144,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-engine/src/main/java/org/junit/platform/engine/ConfigurationParameters.java#L111-L144","documentation":"ConfigurationParameters.get(String, Function) lets a caller read a config value and transform it (e.g. parse to int/boolean/duration). If the transformer throws any Exception while applied to the raw string value, it is wrapped in a JUnitException naming the key and the offending value. This is the engine's generic typed-access failure for configuration parameters.","triggerScenarios":"Calling configurationParameters.get(key, transformer) where the stored value cannot be transformed — e.g. get(\"timeout\", Integer::parseInt) with a non-numeric value; a custom transformer that throws IllegalArgumentException on invalid enum names; a duration transformer given a malformed unit.","commonSituations":"A user sets --config junit.foo.bar=someGarbage and an extension/engine tries to parse it; build-tool (Gradle/Maven) plugins passing through a mistyped value; a defaults file with a stale value after upgrading an extension that changed the expected format.","solutions":["Inspect the error message for the exact key and initial value, then correct the value at its source (system property, junit.properties, --config, build config).","Prefer the typed helpers where available — getBoolean(key) is more forgiving than a hand-written parser.","If you own the transformer, make it throw a clear IllegalArgumentException with guidance for valid values, so the wrapped message is actionable.","Confirm the configuration parameter key name matches the extension's documented property (typos yield the raw string hitting the transformer)."],"exampleFix":"// before\nString raw = config.get(\"junit.jupiter.execution.timeout.test.method.mode\").orElse(null);\nint n = Integer.parseInt(raw); // throws if raw is \"adada\"\n// after — use the typed accessor / safe transform\nboolean parallel = config.getBoolean(\"junit.jupiter.execution.parallel.enabled\").orElse(false);\nOptional<Integer> n = config.get(\"my.count\", Integer::parseInt); // JUnitException names key+value on failure","handlingStrategy":"try-catch","validationCode":"// Validate config values you control before they reach an engine/extension that will transform them.\nString raw = config.get(\"my.extension.count\").orElse(null);\nif (raw != null) {\n  try { Integer.parseInt(raw); }\n  catch (NumberFormatException e) { throw new IllegalArgumentException(\"my.extension.count must be an integer, got: \" + raw); }\n}\n","typeGuard":null,"tryCatchPattern":"// Catch JUnitException around the typed accessor when user-supplied values may be invalid.\ntry {\n  Optional<Integer> n = configurationParameters.get(\"my.extension.count\", Integer::parseInt);\n} catch (org.junit.platform.commons.JUnitException e) {\n  // message names the key and the offending value\n  throw new IllegalArgumentException(e.getMessage(), e);\n}","preventionTips":["Prefer built-in typed accessors (getBoolean) over hand-rolled parsers.","Document every configuration parameter's expected format in your extension's user guide.","Surface transformer failures with actionable IllegalArgumentException messages from your own transformer."],"tags":["configuration","engine","config-parameters"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}