{"record":{"id":"689abae3f9fd80ff","repo":"junit-team/junit5","slug":"implement-generatedisplaynameformethod-list-class","errorCode":null,"errorMessage":"Implement generateDisplayNameForMethod(List<Class<?>>, Class<?>, Method) instead","messagePattern":"Implement generateDisplayNameForMethod\\(List<Class<\\?>>, Class<\\?>, Method\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/DisplayNameGenerator.java","lineNumber":164,"sourceCode":"\t/**\n\t * Generate a display name for the given method.\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 class instance supplied as {@code testClass} may differ from\n\t * the class returned by {@code testMethod.getDeclaringClass()} &mdash; for\n\t * example, when a test method is inherited from a superclass.\n\t *\n\t * @param testClass the class the test method is invoked on; never {@code null}\n\t * @param testMethod method to generate a display name for; never {@code null}\n\t * @return the display name for the test; never blank\n\t * @deprecated in favor of {@link #generateDisplayNameForMethod(List, Class, Method)}\n\t */\n\t@API(status = DEPRECATED, since = \"5.12\")\n\t@Deprecated(since = \"5.12\")\n\tdefault String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\"Implement generateDisplayNameForMethod(List<Class<?>>, Class<?>, Method) instead\");\n\t}\n\n\t/**\n\t * Generate a display name for the given method.\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. Similarly, the class instance\n\t * supplied as {@code testClass} may differ from the class returned by\n\t * {@code testMethod.getDeclaringClass()} &mdash; for example, when a test\n\t * method is inherited from a superclass.\n\t *\n\t * @param enclosingInstanceTypes the runtime types of the enclosing","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/DisplayNameGenerator.java#L146-L182","documentation":"Default method of the deprecated two-arg generateDisplayNameForMethod(Class<?>, Method) on DisplayNameGenerator, deprecated since 5.12 in favor of generateDisplayNameForMethod(List<Class<?>>, Class<?>, Method). The default implementation throws UnsupportedOperationException so custom generators must implement the new arity. Hitting it means display-name generation for a method was dispatched to the un-overridden old method.","triggerScenarios":"A custom DisplayNameGenerator selected via @DisplayNameGeneration that does not override the new three-arg method, when JUnit requests a method display name — the inherited default throws.","commonSituations":"Pre-5.12 custom DisplayNameGenerator carried forward after upgrade; generators built by copying an old example that only overrode the two-arg method; parameterized-test display customization that targeted the wrong overload.","solutions":["Override generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod) in your generator.","Subclass Standard/Simple/IndicativeSentences and override only the new method to keep defaults intact.","Remove any override of the deprecated two-arg method to avoid dispatching to it accidentally."],"exampleFix":"// before\n@Override\npublic String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {\n    return testMethod.getName();\n}\n// after\n@Override\npublic String generateDisplayNameForMethod(List<Class<?>> enclosingInstanceTypes,\n        Class<?> testClass, Method testMethod) {\n    return testMethod.getName();\n}","handlingStrategy":"type-guard","validationCode":"assert implementsNewMethod(generator.getClass()) : \"implement new List/Class/Method overload\";","typeGuard":"static boolean implementsNewMethod(Class<? extends DisplayNameGenerator> c) {\n    try {\n        return c.getMethod(\"generateDisplayNameForMethod\", List.class, Class.class, Method.class)\n                 .getDeclaringClass() == c;\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Target the three-arg method overload on upgrade.","Subclass an existing generator to keep defaults intact.","Remove deprecated two-arg overrides to prevent accidental dispatch."],"tags":["display-name","deprecation","unsupported-operation","migration","method-display-name"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}