{"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/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java#L76-L112","documentation":"Thrown by the ParameterizedInvocationNameFormatter constructor when parsing the display name pattern (the 'name' attribute of @ParameterizedTest or @ParameterizedClass) throws an exception. The pattern is parsed into PartialFormatter segments that may contain java.text.MessageFormat sub-patterns for literal text containing curly braces. Invalid MessageFormat syntax in these segments triggers the nested exception.","triggerScenarios":"Setting name = \"{0} test\" or name = \"test {\" on @ParameterizedTest(name=...) or @ParameterizedClass(name=...) where the curly-brace segment is not a valid MessageFormat pattern. For example, an unmatched single brace '{' or a malformed format choice/type specifier.","commonSituations":"Using a display name pattern that contains literal curly braces for formatting but has syntax errors (e.g., '{' without closing '}', '{0,date}' with an unsupported format type). Confusing JUnit placeholders like {index} (which are fine) with MessageFormat patterns like {0}.","solutions":["Use the documented JUnit placeholders: {index}, {displayName}, {arguments}, {argumentsWithNames}, {argumentSetName}, {0}, {1}, etc.","If you need literal curly braces in the display name, escape them as MessageFormat requires: use ''{'' and ''}'' (single-quote escapes)","Simplify the pattern to isolate which segment is malformed, then re-add complexity","Check the nested exception in the stack trace for the exact MessageFormat parse error"],"exampleFix":"// before\n@ParameterizedTest(name = \"test { for {0}\")\nvoid test(int x) { }\n\n// after (escape literal braces or remove them)\n@ParameterizedTest(name = \"test for {0}\")\nvoid test(int x) { }","handlingStrategy":"validation","validationCode":"// Validate the display name pattern before applying it:\nstatic void validateDisplayNamePattern(String pattern) {\n    try {\n        // Test that any literal brace segments parse as MessageFormat\n        if (pattern.contains(\"{\" )) {\n            new MessageFormat(pattern.replaceAll(\"\\\\{index}|\\\\{arguments}|\\\\{displayName\", \"\"));\n        }\n    } catch (Exception e) {\n        throw new IllegalArgumentException(\"Invalid display name pattern: \" + pattern, e);\n    }\n}\n// Simpler: stick to documented placeholders and avoid raw curly braces","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only documented JUnit placeholders: {index}, {displayName}, {arguments}, {argumentsWithNames}, {argumentSetName}, {argumentSetNameOrArgumentsWithNames}","Escape literal curly braces in MessageFormat segments with single quotes: '{' and '}'","Avoid complex MessageFormat type specifiers unless you have tested them","Start with a simple pattern like '[{index}] {arguments}' and add complexity incrementally"],"tags":["parameterized-test","display-name","messageformat","configuration","junit-jupiter-params"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}