{"record":{"id":"2d26e2820bdc76c9","repo":"junit-team/junit5","slug":"implement-generatedisplaynamefornestedclass-list-c","errorCode":null,"errorMessage":"Implement generateDisplayNameForNestedClass(List<Class<?>>, Class<?>) instead","messagePattern":"Implement generateDisplayNameForNestedClass\\(List<Class<\\?>>, Class<\\?>\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/DisplayNameGenerator.java","lineNumber":118,"sourceCode":"\t * @return the display name for the class; never blank\n\t */\n\tString generateDisplayNameForClass(Class<?> testClass);\n\n\t/**\n\t * Generate a display name for the given {@link Nested @Nested} inner test\n\t * class.\n\t *\n\t * <p>If this method returns {@code null}, the default display name\n\t * generator will be used instead.\n\t *\n\t * @param nestedClass the class to generate a name for; never {@code null}\n\t * @return the display name for the nested class; never blank\n\t * @deprecated in favor of {@link #generateDisplayNameForNestedClass(List, Class)}\n\t */\n\t@API(status = DEPRECATED, since = \"5.12\")\n\t@Deprecated(since = \"5.12\")\n\tdefault String generateDisplayNameForNestedClass(Class<?> nestedClass) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\"Implement generateDisplayNameForNestedClass(List<Class<?>>, Class<?>) instead\");\n\t}\n\n\t/**\n\t * Generate a display name for the given {@link Nested @Nested} inner test\n\t * class.\n\t *\n\t * <p>If this method returns {@code null}, the default display name\n\t * generator will be used instead.\n\t *\n\t * @implNote The classes supplied as {@code enclosingInstanceTypes} may\n\t * differ from the classes returned from invocations of\n\t * {@link Class#getEnclosingClass()} &mdash; for example, when a nested test\n\t * class is inherited from a superclass.\n\t *\n\t * @param enclosingInstanceTypes the runtime types of the enclosing\n\t * instances for the test class, ordered from outermost to innermost,\n\t * excluding {@code nestedClass}; never {@code null}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/DisplayNameGenerator.java#L100-L136","documentation":"Default method of the deprecated single-arg generateDisplayNameForNestedClass(Class<?>) on DisplayNameGenerator, deprecated since 5.12 in favor of generateDisplayNameForNestedClass(List<Class<?>>, Class<?>). The default body throws UnsupportedOperationException to force subclasses to implement the new overloaded form rather than relying on the old one. A generator that does not override the new method will abort display-name generation for @Nested classes.","triggerScenarios":"A custom DisplayNameGenerator implementation that overrides neither the old nor the new generateDisplayNameForNestedClass, yet is selected (via @DisplayNameGeneration) for a test class containing @Nested classes — the inherited default method runs and throws.","commonSituations":"Upgrading to JUnit 5.12+ with a pre-existing custom DisplayNameGenerator that only overrode some methods; relying on interface defaults that no longer exist; a generator written for an older API surface.","solutions":["Implement the new signature generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> nestedClass) in your custom DisplayNameGenerator.","Subclass an existing generator (Standard, Simple, IndicativeSentences) and override only what you need, so defaults are inherited correctly.","If you must support the old signature transiently, override both methods and delegate, but plan to remove the old override when you drop pre-5.12 support."],"exampleFix":"// before\n@Override\npublic String generateDisplayNameForNestedClass(Class<?> nestedClass) {\n    return nestedClass.getSimpleName();\n}\n// after\n@Override\npublic String generateDisplayNameForNestedClass(List<Class<?>> enclosingInstanceTypes,\n        Class<?> nestedClass) {\n    return nestedClass.getSimpleName();\n}","handlingStrategy":"type-guard","validationCode":"assert !overridesOnlyOldNested(generator.getClass()) : \"implement new List/Class overload\";","typeGuard":"static boolean implementsNewNested(DisplayNameGenerator g) {\n    try {\n        return g.getClass().getMethod(\"generateDisplayNameForNestedClass\", List.class, Class.class)\n                 .getDeclaringClass() == g.getClass();\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["After a JUnit upgrade, audit custom DisplayNameGenerators for the new arities.","Subclass Standard/Simple/IndicativeSentences to inherit safe defaults.","Override the new List-based overload and delete deprecated overrides."],"tags":["display-name","deprecation","unsupported-operation","migration","nested-tests"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}