{"record":{"id":"c890217f133d30f9","repo":"junit-team/junit5","slug":"this-class-must-not-be-instantiated-c89021","errorCode":null,"errorMessage":"This class must not be instantiated","messagePattern":"This class must not be instantiated","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/MethodOrderer.java","lineNumber":151,"sourceCode":"\t * ordering should be applied.\n\t *\n\t * <p>If the {@value #DEFAULT_ORDER_PROPERTY_NAME} is set, specifying this\n\t * {@code MethodOrderer} has the same effect as referencing the configured\n\t * class directly. Otherwise, it has the same effect as not specifying any\n\t * {@code MethodOrderer}.\n\t *\n\t * <p>This class can be used to reset the {@code MethodOrderer} for a\n\t * {@link Nested @Nested} class and its {@code @Nested} inner classes,\n\t * recursively, when a {@code MethodOrderer} is configured using\n\t * {@link TestMethodOrder @TestMethodOrder} on an enclosing class.\n\t *\n\t * @since 6.0\n\t */\n\t@API(status = EXPERIMENTAL, since = \"6.0\")\n\tfinal class Default implements MethodOrderer {\n\n\t\tprivate Default() {\n\t\t\tthrow new JUnitException(\"This class must not be instantiated\");\n\t\t}\n\n\t\t@Override\n\t\tpublic void orderMethods(MethodOrdererContext context) {\n\t\t\t// never called\n\t\t}\n\t}\n\n\t/**\n\t * {@code MethodOrderer} that sorts methods alphanumerically based on their\n\t * names using {@link String#compareTo(String)}.\n\t *\n\t * <p>If two methods have the same name, {@code String} representations of\n\t * their formal parameter lists will be used as a fallback for comparing the\n\t * methods.\n\t *\n\t * @since 5.7\n\t */","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/MethodOrderer.java#L133-L169","documentation":"Thrown from the private constructor of MethodOrderer.Default, a sentinel/placeholder MethodOrderer introduced in JUnit 6.0 used to reset method ordering for nested classes. Like ClassOrderer.Default it is referenced by type only; constructing it fails fast with a JUnitException.","triggerScenarios":"Calling new MethodOrderer.Default() or constructing it via reflection (ReflectionSupport.newInstance / Constructor.newInstance). The sole private constructor always throws.","commonSituations":"Reflective factories that instantiate every MethodOrderer implementation; copying an instantiation pattern from MethodOrderer.MethodName onto Default; tooling that enumerates nested classes and constructs them.","solutions":["Never instantiate MethodOrderer.Default — reference it by type only, e.g. @TestMethodOrder with the Default sentinel declared by class identity.","If a factory enumerates orderers, skip MethodOrderer.Default (and ClassOrderer.Default) and treat them as no-op sentinels.","Use a concrete MethodOrderer (MethodName, OrderAnnotation, Random, etc.) when you need an instance to call orderMethods on."],"exampleFix":"// before\nMethodOrderer o = new MethodOrderer.Default();\n// after\n// reset nested method ordering by type reference only:\n@TestMethodOrder(MethodOrderer.Default.class)","handlingStrategy":"type-guard","validationCode":"if (ordererType == MethodOrderer.Default.class) {\n    // reference only; do not instantiate\n}","typeGuard":"static boolean isSentinelMethodOrderer(Class<? extends MethodOrderer> c) {\n    return c == MethodOrderer.Default.class;\n}","tryCatchPattern":null,"preventionTips":["Never instantiate MethodOrderer.Default; reference by type only.","Reflective factories must skip Default sentinels.","Pick a concrete MethodOrderer when an instance is required."],"tags":["method-orderer","sentinel","instantiation-forbidden","junit-6","reflection"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}