{"record":{"id":"6982ddc59a81cbf7","repo":"junit-team/junit5","slug":"the-display-name-pattern-defined-for-the-parameter","errorCode":null,"errorMessage":"The display name pattern defined for the parameterized test is invalid. See nested exception for further details.","messagePattern":"The display name pattern defined for the parameterized test is invalid\\. See nested exception for further details\\.","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java","lineNumber":94,"sourceCode":"\t\t\t\t.orElse(512);\n\t\tPreconditions.condition(argumentMaxLength > 0,\n\t\t\t() -> ARGUMENT_MAX_LENGTH_KEY + \" must be a positive number: \" + argumentMaxLength);\n\n\t\treturn new ParameterizedInvocationNameFormatter(pattern, extensionContext.getDisplayName(), declarationContext,\n\t\t\targumentMaxLength);\n\t}\n\n\tprivate final PartialFormatter[] partialFormatters;\n\n\tParameterizedInvocationNameFormatter(String pattern, String displayName,\n\t\t\tParameterizedDeclarationContext<?> declarationContext, int argumentMaxLength) {\n\t\ttry {\n\t\t\tthis.partialFormatters = parse(pattern, displayName, declarationContext, argumentMaxLength);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tString message = \"The display name pattern defined for the parameterized test is invalid. \"\n\t\t\t\t\t+ \"See nested exception for further details.\";\n\t\t\tthrow new JUnitException(message, ex);\n\t\t}\n\t}\n\n\tString format(int invocationIndex, EvaluatedArgumentSet arguments, boolean quoteTextArguments) {\n\t\ttry {\n\t\t\treturn formatSafely(invocationIndex, arguments, quoteTextArguments);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tString message = \"Failed to format display name for parameterized test. \"\n\t\t\t\t\t+ \"See nested exception for further details.\";\n\t\t\tthrow new JUnitException(message, ex);\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"JdkObsolete\")\n\tprivate String formatSafely(int invocationIndex, EvaluatedArgumentSet arguments, boolean quoteTextArguments) {\n\t\tArgumentsContext context = new ArgumentsContext(invocationIndex, arguments.getConsumedArguments(),\n\t\t\targuments.getName(), quoteTextArguments);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java#L76-L112","documentation":"Thrown during construction of ParameterizedInvocationNameFormatter when the display name pattern (set via the 'name' attribute of @ParameterizedTest or @ParameterizedClass, or the junit.jupiter.params.displayName.pattern configuration parameter) cannot be parsed. The parser attempts to break the pattern into PartialFormatter segments (placeholders like {0}, {index}, {arguments}, etc.). Any exception during this parse phase — such as an invalid MessageFormat pattern — is wrapped in this JUnitException with the original cause attached.","triggerScenarios":"Set @ParameterizedTest(name = \"{0}\") where {0} is actually valid, but use an invalid MessageFormat pattern like unbalanced braces (e.g., name = \"{0\") or name = \"{a}\"). Using a placeholder the formatter doesn't recognize, or a pattern with illegal MessageFormat syntax such as '{' without proper quoting.","commonSituations":"Developers customizing display names for parameterized tests with complex patterns. Migration from JUnit 4 parameterized display names that used different placeholder syntax. Copy-pasting a MessageFormat pattern that works in production code but conflicts with JUnit's custom placeholder parsing (which adds {index}, {arguments}, {0}, {arguments-set-name} on top of MessageFormat).","solutions":["Inspect the nested cause exception for the specific parse error — it will identify the exact position and nature of the syntax error","Simplify the pattern to a known-good baseline (e.g., \"#[{index}] {arguments}\") and add complexity incrementally","Ensure all braces in the pattern are balanced and MessageFormat special characters are properly quoted with single quotes","Check that any custom placeholders are supported by the current JUnit version"],"exampleFix":"// before — unbalanced brace in display name pattern\n@ParameterizedTest(name = \"#{index} {0\")\nvoid test(String input) { }\n\n// after — balanced braces\n@ParameterizedTest(name = \"#{index} {0}\")\nvoid test(String input) { }\n\n// For literal braces in MessageFormat, use single quotes:\n@ParameterizedTest(name = \"#[{index}] ''{0}''\")\nvoid test(String input) { }","handlingStrategy":"try-catch","validationCode":"// Validate the display name pattern before running tests\nimport java.text.MessageFormat;\n\nstatic void validateDisplayNamePattern(String pattern) {\n    try {\n        new MessageFormat(pattern);\n    } catch (Exception e) {\n        throw new IllegalArgumentException(\"Invalid display name pattern: \" + pattern, e);\n    }\n    // Check for balanced braces\n    long opens = pattern.chars().filter(c -> c == '{').count();\n    long closes = pattern.chars().filter(c -> c == '}').count();\n    if (opens != closes) {\n        throw new IllegalArgumentException(\"Unbalanced braces in pattern: \" + pattern);\n    }\n}","typeGuard":null,"tryCatchPattern":"// In test infrastructure setup, catch and report invalid patterns early\ntry {\n    validateDisplayNamePattern(pattern);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Display name pattern validation failed for @ParameterizedTest\", e);\n    // Fall back to default pattern\n    pattern = ParameterizedTest.DEFAULT_DISPLAY_NAME;\n}","preventionTips":["Test display name patterns with a simple parameterized test before applying them to complex tests","Use JUnit's built-in placeholders ({index}, {arguments}, {0}) rather than complex MessageFormat syntax","Quote literal braces with single quotes in MessageFormat patterns (e.g., '{0}') to avoid parse errors"],"tags":["display-name","messageformat","pattern","configuration","junit-params"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}